Coding the Leaderboard | Documentation - Roblox Creator Hub (2024)

In-game, player will have important stats they need to see like the items they've collected. These numbers will be displayed using a leaderboard. Leaderboards are built-in features of Roblox that need a script to be activated and customized.

Coding the Leaderboard | Documentation - Roblox Creator Hub (1)

Note that the leaderboard in this experience doesn't save player information in-between sessions. For information on saving player data, you'll need to use an advanced coding concept called data stores.

Setting Up the Leaderboard

Whenever a player is added to the experience, they'll need to be added to the leaderboard along with code for tracking the individual stats.

  1. In the Explorer, under ServerScriptService, create a new script named PlayerSetup. In that script, delete the hello world line and write a descriptive comment.

    Coding the Leaderboard | Documentation - Roblox Creator Hub (2)
  2. After the comment, create a custom function named onPlayerJoin with a parameter named player.

    -- Creates a leaderboard that shows player variables

    local function onPlayerJoin(player)

    end

  3. In onPlayerJoin, create a variable named leaderstats, and have it create a new Folder Instance.

    local function onPlayerJoin(player)

    local leaderstats = Instance.new("Folder")

    end

  4. Name the new Folder instance leaderstats, and parent it to the player. Naming the folder leaderstats lets Roblox Studio know to create a leaderboard.

    local function onPlayerJoin(player)

    local leaderstats = Instance.new("Folder")

    leaderstats.Name = "leaderstats"

    leaderstats.Parent = player

    end

    Because leaderboards are a built-in feature, they must be named exactly as seen. For example, a folder named "leaderboard" wouldn't work.

  5. After the end of the function, connect OnPlayerJoin to the PlayerAdded event. Whenever a player joins the experience, each player will be provided the leaderboard.

    local Players = game:GetService("Players")

    local function onPlayerJoin(player)

    local leaderstats = Instance.new("Folder")

    leaderstats.Name = "leaderstats"

    leaderstats.Parent = player

    end

    Players.PlayerAdded:Connect(onPlayerJoin)

    Don't test yet since you won't see a leaderboard. Because there are no stats to display, the leaderboard won't appear.

Tracking Player Stats

Now that a leaderboard is created, it needs to show the player these numbers:

  • Gold - How much money the player has.

  • Items - How many items the player has collected from the world.

  • Spaces - The most items a player can hold at one time.

Each of these numbers will be an IntValue, a placeholder object for a number.

Coding Player Gold

Start with coding a stat for gold.

  1. In OnPlayerJoin, under leaderstats.Parent = player, type local gold = Instance.new("IntValue"). This creates a new IntValue and stores it in the variable gold.

    local function onPlayerJoin(player)

    local leaderstats = Instance.new("Folder")

    leaderstats.Name = "leaderstats"

    leaderstats.Parent = player

    local gold = Instance.new("IntValue")

    end

  2. Next, type gold.Name = "Gold". This gives the IntValue a name so you can use it in other scripts. The name will also be shown to players on the leaderboard.

    local function onPlayerJoin(player)

    local gold = Instance.new("IntValue")

    gold.Name = "Gold"

    end

    If you decide to use your own stat names, keep track of their exact name and spelling. They'll be referenced later in the series for other scripts.

  3. On a new line, type gold.Value = 0. This sets the starting value for players.

    local function onPlayerJoin(player)

    local gold = Instance.new("IntValue")

    gold.Name = "Gold"

    gold.Value = 0

    end

    While variables are normally changed using = as in myNumber = 10, an IntValue is changed using Value, like myIntValue.Value = 10.

  4. Type gold.Parent = leaderstats. This parents the IntValue for gold to leaderstats. If the IntValue is not parented to leaderstats, players won't see it.

    local function onPlayerJoin(player)

    local gold = Instance.new("IntValue")

    gold.Name = "Gold"

    gold.Value = 0

    gold.Parent = leaderstats

    end

  5. Play your project and notice that a leaderboard appears in the top right.

    Coding the Leaderboard | Documentation - Roblox Creator Hub (3)

Troubleshooting Tips

If you don't see the leaderboard, try the following:

  • Make sure that .Value is capitalized.

  • Make sure that the variable for the IntValue is parented to the leaderboard like gold.Parent = leaderstats.

Coding Items and Spaces

Remember that the stat names can be anything based off the game design document. In other words, "Items" can be "Crystals" instead.

  1. Add a blank line to separate the next stat, then create the item stat by setting up a new IntValue the same way you did for gold.

    local function onPlayerJoin(player)

    gold.Parent = leaderstats

    -- Create the Items stat

    local items = Instance.new("IntValue")

    items.Name = "Items"

    items.Value = 0

    items.Parent = leaderstats

    end

  2. Create a new stat for the player's bag spaces. Set spaces.Value to 2 so players start the experience only being able to hold two items at once, encouraging them buy a new bag as soon as they can.

    local function onPlayerJoin(player)

    items.Parent = leaderstats

    -- Create the Spaces stat

    local spaces = Instance.new("IntValue")

    spaces.Name = "Spaces"

    spaces.Value = 2

    spaces.Parent = leaderstats

    end

  3. Test the project. Players should have a leaderboard showing Gold, Items, and Spaces.

    Coding the Leaderboard | Documentation - Roblox Creator Hub (4)

If the leaderboard doesn't appear, try checking the following below.

  • If you can't see the number on the leaderboard, check that each IntValue is parented to leaderstats.

  • Make sure each IntValue is spelled exactly as shown

  • Check that the PlayerAdded event is at the bottom of the script

Complete PlayerSetup Script

A finished version of the script can be referenced below.

local Players = game:GetService("Players")

-- Creates a leaderboard that shows player variables

local function onPlayerJoin(player)

local leaderstats = Instance.new("Folder")

leaderstats.Name = "leaderstats"

leaderstats.Parent = player

local gold = Instance.new("IntValue")

gold.Name = "Gold"

gold.Value = 0

gold.Parent = leaderstats

local items = Instance.new("IntValue")

items.Name = "Items"

items.Value = 0

items.Parent = leaderstats

local spaces = Instance.new("IntValue")

spaces.Name = "Spaces"

spaces.Value = 2

spaces.Parent = leaderstats

end

-- Run onPlayerJoin when the PlayerAdded event fires

Players.PlayerAdded:Connect(onPlayerJoin)

Coding the Leaderboard | Documentation - Roblox Creator Hub (2024)

FAQs

How do you make a leaderboard script on Roblox? ›

To set up the leaderboard and add players when they enter the experience:
  1. Create a new Script within ServerScriptService and name it Leaderboard.
  2. In the script, connect a function to the PlayerAdded event. ...
  3. Inside the connected function, create a new Folder instance, name it leaderstats, and parent it to the player.

What programming language does Roblox creator use? ›

Roblox uses the coding language Lua. This article will cover how to start coding in Roblox, introducing common concepts like scripts, data types, and variables.

How to make a scoreboard on Roblox Studio? ›

Creating Score Bars
  1. Creating a frame in the top-center of the screen.
  2. Adding a crown icon that communicates what the score bar is tracking without any textual guidance.
  3. Inserting score text that records the amount of gold the player collects.

How to make leaderstats in Roblox Studio? ›

How to make leaderstats in roblox studio | For beginners
  1. Make a server script inside ServerScriptService | game.ServerScriptService. You can name the script however you want, it doesn't matter.
  2. We need to detect if the player joins. ...
  3. Lets make a folder inside the player. ...
  4. Make your currency. ...
  5. We are done!
Jul 2, 2022

What is a global leaderboard? ›

The Global Leaderboard (not to be confused with the server leaderboard, as in Mechanics) is a server-wide scoreboard that allows players to compete for the best statistics.

What is the script code in Roblox? ›

Inserting a Script

Code in Roblox is written in a language called Luau which you can put in scripts within various containers in the Explorer. If you put a script under a Part, Roblox will run the script's code when the part is loaded into the game.

Is Roblox coding easy? ›

Roblox Studio uses Lua as its scripting language because it is easy to learn, fast, and flexible. Lua is a scripting language that is widely used in the gaming industry, and it is well-suited to being embedded in other applications.

Does Roblox use C or C++? ›

Roblox games and the Roblox platform itself are primarily built and scripted using Lua and C++. Python is a popular programming language known for its simplicity and readability. It's the language kids start with in our middle and high school coding programs because it's in demand and easy to learn.

Is Lua easier than python? ›

Conclusion. Lua and Python are both interpreted, dynamically typed, garbage-collected programming languages. Lua is smaller than Python, making it easier to learn and embed. However, Python is better supported and more widely applicable.

What is Roblox money called? ›

Robux are the virtual currency of Roblox and there are ways to purchase or earn Robux. Purchasing Robux: You can purchase Robux in our mobile, browser, PlayStation, and Xbox One apps.

How to copy and paste scripts on Roblox? ›

Press and hold down on the text you want to copy (or double tap fast on a word) and it should highlight one word. Simply drag the highlighted region on either end to extend the box. Then, tap copy once you've highlighted the text. To paste, simple press and hold down on your distracted location and press paste.

How do you film a Roblox game? ›

To record a video, follow these steps:
  1. Go into the experience, click the menu button in the upper-left corner.
  2. In the experience menu, click the Captures tab.
  3. To start recording click Record Video.
  4. You are now recording video, do your thing! ...
  5. To view your video, click the My Videos link in the notification that pops up.

How do you make a world on Roblox studio? ›

Design the World
  1. From the Home tab, open the Terrain Editor.
  2. The editor will open on the left. To paint: ...
  3. Select a material, such as Snow. To paint, left click and drag on any terrain. ...
  4. Paint terrain until your game looks completely different from the original.

What is rigging in Roblox Studio? ›

Rigging is the process of connecting a mesh with an internal poseable skeleton rig and bone structure. Rigged meshes allow mesh surfaces to rotate and move where internal bones are placed within the model during the modeling process.

How do you generate Robux? ›

Design custom clothing for your Roblox avatar to earn extra Robux and generate interest from other players. Limited items can be resold for large amounts of Robux after holding onto them for 30 days. Consider buying a membership for a monthly Robux stipend or purchasing Robux in bulk if needed for in-game purchases.

How do you make a leaderboard? ›

In this guide, we'll show you how to create a quiz that displays a scoreboard and lets users search for the top three performers.
  1. Step1: Create and customize your quiz. ...
  2. Step2: Set up your conditional logic and calculations. ...
  3. Step3: Create your leaderboard app.

What is the leaderboard feature in Roblox? ›

In Roblox, a leaderboard is a display of players' stats. Leaderboard stats often included KOs and WOs, currency, level and experience points, time played, and rounds survived. A leaderboard is created by placing a value named "leaderstats" inside of a player and then placing values inside of that.

How do you use admin script on Roblox? ›

How Do I Use Roblox Commands? Then type “:command” or “:cmds” into the chatbox. Once you've entered either of the two, you can then input whatever Admin Commands and Advanced Commands you'd like. In this instance, “:invisible” is the command, and “me” is the player's game name.

Top Articles
Latest Posts
Article information

Author: Msgr. Benton Quitzon

Last Updated:

Views: 6461

Rating: 4.2 / 5 (63 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Msgr. Benton Quitzon

Birthday: 2001-08-13

Address: 96487 Kris Cliff, Teresiafurt, WI 95201

Phone: +9418513585781

Job: Senior Designer

Hobby: Calligraphy, Rowing, Vacation, Geocaching, Web surfing, Electronics, Electronics

Introduction: My name is Msgr. Benton Quitzon, I am a comfortable, charming, thankful, happy, adventurous, handsome, precious person who loves writing and wants to share my knowledge and understanding with you.