Roblox global leaderboard: top players across every server
Short answer
Store each player's score in an OrderedDataStore keyed by UserId, then read the top entries with GetSortedAsync(false, 50) once every minute or two and show them on a SurfaceGui. Sorted reads have a small budget (5 + players × 2 a minute), so cache the page instead of reading it for every player.
- Make a Part with a SurfaceGui and a ScrollingFrame for the rows.
- Paste the script in ServerScriptService; fill the SurfaceGui from the `top` table in refresh().
- Values must be whole numbers: OrderedDataStore only stores integers.
Copy-paste code
ServerScriptService/GlobalBoard.server.lua
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local board = DataStoreService:GetOrderedDataStore("TopCoins_v1")
local function submit(player)
local coins = player:FindFirstChild("leaderstats") and player.leaderstats.Coins.Value
if coins then pcall(board.SetAsync, board, tostring(player.UserId), math.floor(coins)) end
end
local top = {} -- cached { {name = ..., score = ...}, ... }
local function refresh()
local ok, pages = pcall(board.GetSortedAsync, board, false, 50)
if not ok then return end
local rows = {}
for rank, entry in pages:GetCurrentPage() do
local okName, name = pcall(Players.GetNameFromUserIdAsync, Players, tonumber(entry.key))
rows[rank] = { name = okName and name or "?", score = entry.value }
end
top = rows
-- update your SurfaceGui here from `top`
end
Players.PlayerRemoving:Connect(submit)
task.spawn(function()
while true do
for _, p in Players:GetPlayers() do submit(p) end
refresh()
task.wait(120)
end
end)Good to know
Names: GetNameFromUserIdAsync is a web call; cache names by UserId so a refresh doesn't look up the same 50 names every time.
Weekly boards: put the week number in the store name ("TopCoins_2026w42") so each week starts empty.
Studwright: Roblox systems that never lose saves
from $12Studwright is 16 tested Luau modules: session-locked SaveData, Receipts (developer products granted once), Codes, DailyRewards, PlaytimeRewards, Leaderboard, LootTable, Inventory, Currency, RemoteGuard and more, as a drag-in .rbxmx with the tests.
Secure checkout · 14-day fix-or-refund if it doesn't work as described (terms)Questions
Why is my global leaderboard empty?
OrderedDataStore needs integer values, and Studio needs API Services enabled. Check that SetAsync is being called with math.floor().
How many entries can I show?
GetSortedAsync returns up to 100 per page.
Can I sort ascending (fastest time)?
Yes: GetSortedAsync(true, 50).
Free: the Roblox Starter Kit
7 free Luau modules (damage, pets, shop formatting, admin audit log, tycoon guards and more) plus 3 free calculators, then 5 short emails with the scripting fixes we see go wrong most often.