Show each player's stats at the top-right of the screen, and update them from scripts.
The little list at the top-right of every Roblox game — the one showing each player's score or cash — is called the leaderboard. It's the first place you'll see your data working, and it's built from a folder called leaderstats.
Every player object in Roblox automatically carries a folder: player.leaderstats. Whatever you put inside it shows up on the leaderboard. The recipe is:
leaderstats folder.Value of that NumberValue, and the leaderboard updates itself.What exactly does Roblox look for to show a leaderboard?
A player joining is an event — PlayerAdded:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = player
local coins = Instance.new("NumberValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = stats
end)
game:GetService("Players") — the service that manages players.Players.PlayerAdded:Connect(function(player) ... end) — an event; player is the new player.Instance.new("Folder") creates a Folder named leaderstats, parented to the player.Instance.new("NumberValue") creates a NumberValue named Coins, set to 0, parented into the folder.Roblox looks for a Folder with that exact name inside each player. Misspell it — Leaderstats, leaderStats — and nothing shows. The name is a contract.
The folder must be named exactly (all lowercase) or the leaderboard won't render.
The magic: change the NumberValue's Value, and the leaderboard updates live.
local coin = workspace.Coin
coin.ClickDetector.MouseClick:Connect(function(player)
local coins = player.leaderstats.Coins
coins.Value = coins.Value + 10
end)
player.leaderstats.Coins reaches into the player's folder and grabs the NumberValue. You read it, add 10, write it back. The leaderboard reflects it instantly.
A player wins a round. Write the line that gives them 100 more coins on the leaderboard. Start from their Coins value.
-- reward the player
PlayerAdded — at that moment you have the player object.leaderstats is special.Next: getting to know the player themselves — the Players service.