Lesson 3 of 5
Leaderboards and badges
Add a global coin leaderboard to Beacon Yard with an OrderedDataStore and the PlayerList's Global view, and award badges safely with BadgeService and clear award rules.
By the end you can
- Build a global leaderboard on an OrderedDataStore, write scores from the server and read the top entries with GetSortedAsync
- Stay inside the ordered data store budgets by caching names and refreshing on a timer
- Create and award badges from the server with the right checks, and choose what deserves a badge
Before this: ProfileStore: the library pros use
Step 1 of 11
The leaderboard forgets you
Open the player list in Beacon Yard. It shows Coins next to every player in the server. Close the server and that ranking is gone; start a new one and you are alone at the top. The PlayerList reads leaderstats, which is a session display, not a saved ranking1.

Select a numbered pin, or a row below, to read what it marks.
The player list in a Studio test: one row per player, with the Coins column read from leaderstats.
What does the PlayerList's Here view rank?
Press 1 to 4 to choose, Enter to check.
Step 2 of 11
An ordered data store
A normal DataStore can list its keys with ListKeysAsync, but it cannot hand back entries sorted by value. An Ordered data storeOrdered data storeA DataStore whose values are whole numbers and that can return its entries sorted.Think of it as a scoreboard that sorts itself when you ask. stores whole numbers and can return its entries sorted, a page at a time2. You get one with DataStoreService:GetOrderedDataStore(name), write with SetAsync or UpdateAsync, and read with GetSortedAsync(ascending, pageSize), where the page size is at most 1003.
local board = DataStoreService:GetOrderedDataStore("BeaconYard_v1_board")
-- Server only, when a match ends: write the coins earned in that match.
pcall(function()
board:SetAsync(tostring(player.UserId), math.floor(haul))
end)
-- Read the top 10, highest first.
local ok, pages = pcall(function()
return board:GetSortedAsync(false, 10)
end)
if ok then
for rank, entry in pages:GetCurrentPage() do
print(rank, entry.key, entry.value)
end
end
Use a separate store name from the profiles. The value is a number the server works out, never one a client sends. In Beacon Yard it is each player's best coin haul from one match, not their coin balance: MatchService passes the coins earned during the match, and LeaderboardService.record uses UpdateAsync so a lower match score never overwrites a player's best haul. A balance would rank whoever has played longest.
function LeaderboardService.record(player: Player, score: number): boolean
local ordered = getStore()
local whole = math.floor(score)
if ordered == nil or whole <= 0 then
return false
end
local ok, err = pcall(function()
ordered:UpdateAsync(tostring(player.UserId), function(previous: unknown): number?
if typeof(previous) == "number" and previous >= whole then
return nil
end
return whole
end)
end)
if not ok then
warnOnce("Could not save the score for " .. tostring(player.UserId) .. " (" .. tostring(err) .. ").")
end
return ok
Where should the leaderboard score come from?
Press 1 to 4 to choose, Enter to check.
Step 3 of 11
The PlayerList can show it for you
Roblox's PlayerList now has Friends and Global views next to Here. In a beta, you register one ordered data store per experience in Creator Hub, and the PlayerList ranks players from it. Each player needs one numeric score, keyed by their user id, written by your server1. Roblox reads the scores but never writes them, so validation stays your job.
For a board in the world, such as a sign in the lobby, you still read GetSortedAsync yourself and draw it on a SurfaceGui.
Go deeper Keys that identify one player
The Global view needs each key to identify exactly one player, by user id, either directly or in a consistent format that contains it. A key like Player_1234 works if every entry uses the same pattern. Mixed formats leave players off the board.
For the PlayerList's Global view, which of these are your job?
Press 1 to 4 to choose, Enter to check.
Step 4 of 11
Refresh on a timer
Sorted reads are the most limited DataStore call. Each server may call GetSortedAsync about 5 + 2 × players times a minute by default, and ordered writes default to 30 + 5 × players per server per minute4. A board that refreshes every frame, or every time anyone earns a coin, burns that in seconds.
The ordered store has its own small data plan. Refresh the board once a minute, cache the player names you looked up, and write a player's score when something meaningful happens, such as leaving or finishing a round.
Think of it as A prepaid data plan that tops up every minute
Stored dataRemember: DataStore budget is a prepaid data plan that tops up every minute.
A lobby server with 3 players refreshes one board. What is the shortest refresh interval, in whole seconds, that stays within 5 + 2 × players sorted reads a minute?
Step 5 of 11
When the plan runs out
Where does it break?“A prepaid data plan that tops up every minute” is a good picture of datastore budget. Where does it stop being true?
It breaks here. Running out is not an immediate error: requests wait in a queue and get slower, and only fail once the queue is full.
The true model. Standard data stores allow 300 + 40 x concurrent users reads and 300 + 20 x concurrent users writes per minute for the whole experience, shared with Open Cloud. UpdateAsync spends one of each.
A phone plan stops working cleanly when you run out. The DataStore budget does not: requests over the limit wait in a queue, the call simply yields longer, and only when a queue passes 30 requests do calls start failing with an error4. So the first symptom is a slow board or a slow save, not an error, which is why it is easy to miss in a test with one player.
Your board refreshes too often. What do you see first?
Press 1 to 4 to choose, Enter to check.
Step 6 of 11
Badges
A BadgeBadgeAn award a player gets for a goal in your experience, shown in their Roblox inventory.Think of it as a sticker on the player's account, not in the game. is an award that appears in the player's Roblox inventory. You create it in Creator Hub on the experience's page: a 512 by 512 image, cropped to a circle, a name and a description. Each experience can create 5 badges free in a 24-hour period (GMT); more cost 100 Robux each5.
You award one with BadgeService:AwardBadgeAsync(userId, badgeId). It only works when the player is in the server, does not own the badge yet, the badge is enabled, it belongs to this experience, and the call comes from a server script. Its limit is 50 + 35 × users per minute6.
local function award(player, badgeId)
local okInfo, info = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, badgeId)
if not okInfo or not info.IsEnabled then
return
end
local okOwned, owned = pcall(BadgeService.UserHasBadgeAsync, BadgeService, player.UserId, badgeId)
if okOwned and not owned then
pcall(BadgeService.AwardBadgeAsync, BadgeService, player.UserId, badgeId)
end
end
A LocalScript calls AwardBadgeAsync when the player defeats the drone. What happens?
Press 1 to 4 to choose, Enter to check.
Step 7 of 11
What deserves a badge
Badges work best for moments a player remembers: surviving a first drill, downing the drone, a hundred rounds. They work badly as participation trophies for joining, because a badge every player has means nothing. Award them right after the server has confirmed the moment, outside any DataStore transform, and only once.
Two fit Beacon Yard well, and both ship in the m12-money milestone: First drill survived (BADGE_FIRST_DRILL), awarded in RoundService when a drill ends and the player is still alive, and Drone down (BADGE_DRONE_DOWN), awarded in CombatService to the player whose wrench swing destroys the drone.
local BADGE_IDS: { [BadgeKey]: number } = {
FIRST_DRILL = Ids.BADGE_FIRST_DRILL,
DRONE_DOWN = Ids.BADGE_DRONE_DOWN,
}
local BadgeAwards = {}
Go deeper Badge icons
A badge icon is a 512 by 512 image that Roblox crops to a circle, so keep the important part of the artwork inside the circle. Disabled badges are not shown on the game page and cannot be earned until you enable them.
Which would make good Beacon Yard badges?
Press 1 to 5 to choose, Enter to check.
Step 8 of 11
Other ways to rank and reward
Other ways pros do this
| Option | What it is | When pros pick it | Trade-offs |
|---|---|---|---|
| OrderedDataStore | Persistent integer scores, sorted on request. | All-time and long-lived boards; the PlayerList's Global view. | Small sorted-read budget; refresh on a timer. |
| MemoryStore sorted map | A fast, shared, expiring sorted map. | Live boards that change every few seconds, such as this hour's best drill. | Entries expire and the memory quota is small; never the only copy. |
| Badges | Platform awards shown in the player's inventory. | Milestones that should be visible outside the game. | 5 free per day to create; slow API; cannot be taken back once a player has one. |
| In-game achievements | Flags in the player's profile, shown in your own UI. | Many small goals, or rewards that unlock items. | Invisible outside the game; you build the UI. |
How do studios reset a weekly leaderboard without deleting keys?
Press 1 to 4 to choose, Enter to check.
Step 9 of 11
Build along: a board and two badges
Build along
src/server/BadgeAwards.luausrc/shared/Ids.luausrc/server/RoundService.luausrc/server/CombatService.luau
Read
src/server/LeaderboardService.luauatm11-two-places. It is already in the starting point, so it is not part of the m11 to m12 diff, and this step only reads. Notice thatMatchServicecallsLeaderboardService.record(player, haul)at the end of a match instead of connecting a secondPlayerRemovinglistener: twoPlayerRemoving:Connecthandlers have no guaranteed order, so a separate listener can raceDataServiceending the session.You should see LeaderboardService.luau writes best match hauls via MatchService at match end and refreshes the lobby board every 60 seconds with cached names.
Create the two badges in Creator Hub on your test experience, then add
BADGE_FIRST_DRILLandBADGE_DRONE_DOWNtoIds.luauat 0 and put your real ids only inIds.local.luau.You should see Ids.luau lists BADGE_FIRST_DRILL and BADGE_DRONE_DOWN at 0, and your real ids are only in Ids.local.luau.
Create
src/server/BadgeAwards.luauwithBadgeAwards.award(player, key)andBadgeAwards.start(), keeping a per-playertriedtable cleared onPlayerRemoving.You should see BadgeAwards.luau checks IsEnabled and UserHasBadgeAsync inside pcall on a spawned thread, and skips duplicate attempts per session.
Call
BadgeAwards.award(player, "FIRST_DRILL")inRoundService.luauwhen a player survives a drill, andBadgeAwards.award(player, "DRONE_DOWN")inCombatService.luauwhen a player's wrench swing destroys the drone.You should see Surviving a drill awards BADGE_FIRST_DRILL once, and the finishing wrench swing on the drone awards BADGE_DRONE_DOWN once.
Step 10 of 11
Challenges
Level 2, Builder
Challenge
Show the global top five on a sign in the yard.
- Start from
- The game at milestone m11 (download)
Done means
- A SurfaceGui on a sign near the shop lists the top five names and scores
- It refreshes once a minute from the server
- Names are looked up once and cached
Meet the criteria above, then record your own result. No test grades this check.
Level 3, Professional
Challenge
Write the scoring and award rules as pure functions in the learner file. Start from the m14-ship tag in the game repo, and see the solution in challenges/solutions/leaderboards-badges.md. The capstone's capstone_leaderboard challenge builds on the same ideas.
- Start from
- The game at milestone m14 (download)
- Grade it
- In Studio, press Play, then run
game.ServerScriptService.RunGameTests:Invoke("leaderboards-badges", "leaderboards-badges-rules")in the server command bar. Copy the pass code from Output.
Done means
- challenges/work/leaderboard_badges.luau turns a coin amount into a whole, valid ordered score: rounded down, and 0 for a negative number, NaN or infinity
- It lists the badges a round earns in this order: FIRST_DRILL when the player survived, then DRONE_DOWN when the drone went down. A badge already owned is left out
- It never changes the owned table it is given (the test passes a frozen one)
- It turns entries, best first, into rows that read "1. Mira - 155" (rank, name, score), with rank 1 on the first row and no rows for no entries
- challenges/leaderboards-badges.luau prints TEST PASS for every check
You create 7 badges for one experience on the same day (GMT). How many Robux does it cost?
Step 11 of 11
Recap
Retiring the analogy
You no longer need “a prepaid data plan that tops up every minute”. Standard data stores allow 300 + 40 x concurrent users reads and 300 + 20 x concurrent users writes per minute for the whole experience, shared with Open Cloud. UpdateAsync spends one of each.
Recap
- leaderstats ranks only this server; an OrderedDataStore of whole-number scores, written by the server, makes a global board and can feed the PlayerList's Global view.
- Sorted reads are scarce (about 5 + 2 × players per server per minute): refresh on a timer and cache names.
- Award badges from the server after the moment is confirmed, check enabled and owned first, and save them for real achievements.
DataStore budget is a prepaid data plan that tops up every minute, until running out is not an immediate error: requests wait in a queue and get slower, and only fail once the queue is full.
Queued for review