PcoWSkbVqDnWTu_dm2ix

In-Game Leaderboards

In-Game Leaderboards

5 min

Roblox has a built-in leaderboard system that lets you display player information like scores, currency, or the fastest time in a race.

Leaderboard Setup

Whenever a player enters the game, they should be added to the leaderboard. This can be done as follows:

  1. Create a new Script within ServerScriptService.
  1. In the script, connect a function to the Players/PlayerAdded|PlayerAdded event.
  1. Inside the connected function, create a new Folder instance, name it leaderstats, and parent it to the player.

Adding Stats

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.

In the leaderboardSetup() function, add the highlighted code:

These lines accomplish the following:

  1. An IntValue instance is created.
  2. The instance’s Instance/Name|Name is set to Gold. This is exactly how the stat will appear on the in-game leaderboard.
  1. The stat’s initial IntValue/Value|Value is set to 0. This can be set to any value you wish, including a value stored in a /articles/saving data introduction|data store if you’re implementing persistent leaderboards.
  1. 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.

Updating Stats

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 LocalScript within StarterGui or StarterPlayerScripts containing a call to StarterGui/SetCoreGuiEnabled|StarterGui:SetCoreGuiEnabled():

Tags:
  • leaderboard
  • points
  • stats
  • score