Forest Logo
search
package_2

simpleleaderboard

By @lucasx150

Roblox

Mirrored from Wally

SimpleLeaderboard

Global leaderboards - minimal setup required, but fully customizable if needed.

Usage

local SimpleLeaderboard = require(ServerScriptService.ServerPackages.SimpleLeaderboard)

SimpleLeaderboard.new({
	Name = "Cash",
	GetStat = function(player)
		return MyDataLayer.Get(player, "Cash")
	end,
	Renderer = SimpleLeaderboard.BoardRenderer.new({
		Container = leaderboardGui.Frame.ScrollingFrame,
		Template = ReplicatedStorage.Templates.LeaderboardEntry,
	}),
})

The board starts automatically, saving online players' Cash every SaveInterval seconds and refreshing the UI every UpdateInterval seconds.

SimpleLeaderboard.new(config: BoardConfig): Board

FieldTypeDefaultNotes
NamestringrequiredUsed as the OrderedDataStore name unless OrderedStore is given
GetStat(Player) -> number?requiredReads the current stat value for a player
Renderer(entries: {LeaderboardEntry}) -> ()noneUpdates the Leaderboard UI. Build one with SimpleLeaderboard.BoardRenderer.new(...), or pass your own function. Omit it for a save-only board - no UI update loop runs
SaveCondition(value: number) -> booleanalways saveIf false, the value will not be saved to the OrderedDataStore
Serializer(value: any) -> numberidentityApplied before writing to OrderedDataStore
Deserializer(value: number) -> anyidentityInverse of Serializer, applied when reading entries back
PageSizenumber25OrderedDataStore page size
SaveIntervalnumber (seconds)720How often players' stats are saved. Warns below 30
UpdateIntervalnumber (seconds)540How often the UI is refreshed. Warns below 30
OrderedStoreOrderedDataStoreBased on Name

Methods

  • Board:Start() - begins the save loop and the UI update loop. Boards start automatically by default.
  • Board:Stop() - halts both loops; safe to Start() again later.
  • Board:Destroy() - stops and permanently disables the board.

SimpleLeaderboard.BoardRenderer.new(config: RendererConfig): Renderer

Builds a default renderer for a ScrollingFrame of cloned template entries.

FieldTypeDefaultNotes
ContainerScrollingFramerequired
TemplateGuiObjectrequired unless a default is setNeeds Title/Rank/Value descendants for the default GuiFormatter
GuiFormatter(GuiObject, entry: LeaderboardEntry) -> ()fills Title/Rank/Value, top-3 gold/green/teal highlightFills in a player's leaderboard entry - both its text and its appearance. The deserialized value is entry.Value

SimpleLeaderboard.BoardRenderer.Multi(config: MultiRendererConfig): Renderer

Like BoardRenderer.new, but renders the same entries into several containers - for a leaderboard shown on more than one board in the world. Every container gets its own rows, cloned from the same Template.

SimpleLeaderboard.new({
	Name = "Cash",
	GetStat = getCash,
	Renderer = SimpleLeaderboard.BoardRenderer.Multi({
		Containers = {
			workspace.Lobby.CashBoard.SurfaceGui.ScrollingFrame,
			workspace.Shop.CashBoard.SurfaceGui.ScrollingFrame,
		},
		Template = ReplicatedStorage.Templates.LeaderboardEntry,
	}),
})
FieldTypeDefaultNotes
Containers{ScrollingFrame}requiredAt least one
TemplateGuiObjectrequired unless a default is setSame as in RendererConfig
GuiFormatter(GuiObject, entry: LeaderboardEntry) -> ()the default formatterSame as in RendererConfig

Defaults

  • BoardRenderer.SetDefaultTemplate(template: GuiObject) - sets a fallback Template so it doesn't need to be passed to every RendererConfig.
  • BoardRenderer.SetDefaultGuiFormatter(formatter: GuiFormatter) - same, for GuiFormatter.
  • BoardRenderer.DefaultGuiFormatter - the built-in formatter, so a custom one can call it and then adjust.

SimpleLeaderboard.Serialize

Pairs of (Serializer, Deserializer) for stats that don't fit directly into an OrderedDataStore's integer storage:

  • Serialize.Log(precision: number?) - stores via log10, for stats that can exceed 2^63 (e.g. cash). Lossy past precision digits.
  • Serialize.Negatives(bias: number?) - shifts negative-capable stats into non-negative range.
  • Serialize.Divide(factor: number?) - divides by a fixed factor, for stats with more precision than integer storage allows (e.g. thousandths).

SimpleLeaderboard.StatSource

A helper for data layers that store multiple stats under one general accessor (e.g. ProfileStore-style profile.Data[key]). Wrap it once and get a GetStat function per key, instead of writing a closure for every board.

local stats = SimpleLeaderboard.StatSource.new(function(player, key)
	local profile = ProfileStore:GetProfile(player)
	return profile and profile.Data[key]
end)

SimpleLeaderboard.new({
	Name = "Cash",
	GetStat = stats:GetStat("Cash"),
	...
})

SimpleLeaderboard.new({
	Name = "Rebirths",
	GetStat = stats:GetStat("Rebirths"),
	...
})
  • StatSource.new(source: (Player, key: string) -> number?): StatSource
  • StatSource:GetStat(key: string): StatGetter - returns a (Player) -> number? bound to key, for use as a BoardConfig.GetStat.

Package Details

Install command (Click to copy)


Version

0.1.2

License

MIT

check_circle

Safe for commercial use

infoThe package archive does not include its license text; the license is declared in its manifest metadata.

Automated license review — not legal advice.