Skip to content

Leaderstats⚓︎

Leaderstats/Leaderboard is the board that appears on the right top of the player's screen. If you are used to playing games on Roblox then you must have seen this in many games.

How to create one?⚓︎

Making a leader stats is pretty simple. First of all we will add a script in ServerScriptService.

For making leader stats, we have to add a folder inside every player and name it leaderstats. Once made the folder, we will add value objects such as IntValue, NumberValue, StringValue etc.

In the script, we will get every player that joins the game and create leader stats for it. To get each player, we will connect a function to PlayerAdded. In the function, we will create the folder for leader stats and set values inside it.

local function stats_handler(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local points = Instance.new("IntValue")
    points.Name = "Points"
    points.Parent = leaderstats
end

game.Players.PlayerAdded:Connect(stats_handler)

In the first part of stats_handler we created a folder using instance.new() and named it leaderstats and lastly parented it to the Player. The player was returned by PlayerAdded. In the second part, we created an IntValue, named it "Points" and set its parent to the leaderstats folder.

Now, if you press f5 to run the game. You can see leaderstats on your screen.

Caution

The folder must be exactly named as leaderstats. In case of any misspelling or capitalizing, the Roblox engine will not create the leaderboard.

Setting Values⚓︎

Once created leaderstats you can set values by changing the Value property of IntValue.

local function stats_handler(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local points = Instance.new("IntValue")
    points.Name = "Points"
    points.Parent = leaderstats
    points.Value = 100
end

game.Players.PlayerAdded:Connect(stats_handler)

No, if you run the game. Your points will be 100.

Implementing⚓︎

As an example of usage. Create a part in the workspace and add ClickDetector to it. You can either make a separate script or use the ordinary one. We will use MouseClick event of ClickDetector which is fired whenever a player interacts with it. This event also returns that Player.

workspace.Part.ClickDetector.MouseClick:Connect(function(player)
    player.leaderstats..Points.Value = player.leaderstats.Points.Value + 1
end)
Now every time you click the part. It will increase your points by 1

Closing!⚓︎

As always, we hope you enjoyed reading and can utilize leaderstats according to your needs. Whatever you are learning, please practice it on the spot. Just reading will not help you if you aren't practicing them. In case of any mistakes, typos, etc please report the article!