Skip to content

Leaderboard configuration โ€‹

Configure Server.Leaderboard in PlayerStateConfig. API usage: Server leaderboard ยท Leaderstats & paths.

Leaderboard config required

Without a proper Leaderboard section, leaderboard functions return nil, {}, or false and may warn in the console.

Basic setup โ€‹

lua
-- PlayerStateConfig.lua
local Config = {
    Server = {
        Leaderboard = {
            Enabled = true,
            DataStoreName = "PlayerState_Leaderboards",
            TrackedStats = {
                "Coins",
                "Level",
                "HighScore",
                "Plot.Likes",
                "Stats.TotalPlayTime",
            },
            SyncInterval = 60,
            UpdateOnPlayerLeave = true,
        },
    },
}

Options โ€‹

SettingDefaultDescription
EnabledtrueMust be true for leaderboards to work
DataStoreName"PlayerState_Leaderboards"Base name for leaderboard DataStores
TrackedStats{ "Coins", "Level", ... }Numeric paths to track
SyncInterval60Sync interval in seconds
UpdateOnPlayerLeavetrueUpdate when players leave

TrackedStats โ€‹

Only numeric paths that exist in your data (or reconcile defaults) are valid:

lua
TrackedStats = {
    "Coins",
    "Plot.Likes",
    "Stats.TotalPlayTime",
}
  • Nested paths use dot notation.
  • An empty array disables tracking.

DataStore names โ€‹

Each stat gets an OrderedDataStore derived from DataStoreName:

  • "Coins" โ†’ PlayerState_Leaderboards_Coins
  • "Plot.Likes" โ†’ PlayerState_Leaderboards_Plot_Likes

DataStore limits

Roblox rate limits apply. Use a sensible SyncInterval for your player count.

Automatic vs manual updates โ€‹

  • Automatic (recommended): Tracked stats sync on the configured interval and on leave when UpdateOnPlayerLeave is true.
  • Manual: PlayerState.UpdateLeaderboard(player, statName, score) for special cases.

Testing โ€‹

lua
Leaderboard = {
    Enabled = true,
    DataStoreName = "PlayerState_Leaderboards_TEST",
    TrackedStats = { "Coins", "Level" },
    SyncInterval = 30,
    UpdateOnPlayerLeave = true,
}

Runtime validation โ€‹

At runtime, PlayerState checks Enabled and whether the stat is in TrackedStats. Misconfiguration returns safe defaults and console warnings instead of throwing.

lua
local board = PlayerState.GetLeaderboard("Coins", 10) -- OK if Coins is tracked

Back to Configuration.

PlayerState - High-Performance Roblox Data Management