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
1The 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?
Answer
Players in the current server, from their leaderstats folders. leaderstats is a folder on each Player in this server. The Here view ranks those. Friends and Global need a persistent store.
Open this step in lesson mode · Link to this step · This confused me
2An 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?
Answer
A number the server works out itself, such as the coins a player earned in a match. The server's own calculation is the truth. Anything a client sends can be forged, and the HUD and leaderstats are display copies.
Open this step in lesson mode · Link to this step · This confused me
3The 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?
Answer
Writing each player's score to the ordered data store from the server; Validating scores before they are written; Registering the store in Creator Hub. You write and validate scores and register the store. Roblox draws Friends and Global in the PlayerList from it.
Open this step in lesson mode · Link to this step · This confused me
4Refresh 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.
local function sortedPerMinute(players) return 5 + 2 * players end
local function orderedWritesPerMinute(players) return 30 + 5 * players end
for _, n in { 1, 8 } do
print("players " .. n .. ": " .. sortedPerMinute(n) .. " sorted reads, "
.. orderedWritesPerMinute(n) .. " ordered writes per minute")
end
-- A board that refreshes every 2 seconds needs:
print("every 2 s: " .. 60 / 2 .. " sorted reads per minute")
players 1: 7 sorted reads, 35 ordered writes per minute
players 8: 21 sorted reads, 70 ordered writes per minute
every 2 s: 30 sorted reads per minuteA 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?
Answer
6. 5 + 2 × 3 = 11 reads a minute, so one read every 60 / 11 ≈ 5.5 seconds, or 6 seconds rounded up. Studios refresh far less often, usually once a minute.
Open this step in lesson mode · Link to this step · This confused me
5When 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?
Answer
Calls take longer because they wait in a queue; errors come only once the queue is full. Over-budget requests are queued and the call keeps yielding. Errors 301 to 306 appear only when a queue's 30 slots are full.
Open this step in lesson mode · Link to this step · This confused me
6Badges
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?
Answer
It fails: badges can only be awarded from server scripts. Awarding is server-only. The server decides the drone was defeated (its health reached 0 from server-checked hits) and awards from there.
Open this step in lesson mode · Link to this step · This confused me
7What 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?
Answer
Survive your first drill; Down the drone; Collect 1,000 coins in total. Surviving, downing the drone and a coin total are achievements. Joining and opening a menu happen to everyone, so they say nothing.
Open this step in lesson mode · Link to this step · This confused me
8Other 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?
Answer
Write to a new ordered store each week, with the week number in its name. A name like BeaconYard_board_2026w46 starts empty each week. Old weeks stay readable for a hall of fame, and nothing has to be deleted.
Open this step in lesson mode · Link to this step · This confused me
9Build 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.
Open this step in lesson mode · Link to this step · This confused me
10Challenges
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
Hints
- The server builds the SurfaceGui, so every client sees the same board.
- GetNameFromUserIdAsync yields; wrap it in pcall.
- Do not read the store from the client: it cannot.
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
Hints
- Ordered stores take whole numbers: floor, and never below 0. NaN is not equal to itself, so test it before you floor.
- A badge already owned is never in the award list.
- Rank 1 is the first row, not 0.
You create 7 badges for one experience on the same day (GMT). How many Robux does it cost?
Answer
200 Robux. The first 5 are free and the 2 extra cost 100 Robux each, so 200 Robux.
Open this step in lesson mode · Link to this step · This confused me
11Recap
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
Open this step in lesson mode · Link to this step · This confused me