Roblox has a built-in leaderboard system that lets you display player information like scores, currency, or the fastest time in a race.
Whenever a player enters the game, they should be added to the leaderboard. This can be done as follows:
- Create a new
- In the script, connect a function to the
- Inside the connected function, create a new
Folderinstance, name it leaderstats, and parent it to the player.
Leaderboards use value type objects to store and display player stats. This script will show a player’s gold using an
IntValue, a placeholder for an integer.
leaderboardSetup() function, add the highlighted code:
These lines accomplish the following:
IntValueinstance is created.
- The instance’s
Instance/Name|Nameis set to Gold. This is exactly how the stat will appear on the in-game leaderboard.
- The stat’s initial
IntValue/Value|Valueis set to 0. This can be set to any value you wish, including a value stored in a
/articles/saving data introduction|data storeif you’re implementing persistent leaderboards.
StringValuemust be set through their Value property as in
gold.Value = 0, not by direct declaration as in
gold = 0.
- The instance is parented to the leaderstats folder which adds it to the leaderboard. When players enter the game, their names will appear on the board.
To update a player’s leaderboard stat, simply change the Value property of that stat within their leaderstats folder. For example, the following
Script can be attached to any pickup object to increase the Gold stat of whichever player collects it.
Hiding the Leaderboard
If you ever want to hide the leaderboard, such as on a menu screen or during a cutscene, place a
StarterPlayerScripts containing a call to