BETA mahshid.de is still being built – things may change or wobble.Still under construction. Feedback
DE
Lesson 9 of 11 · Advanced

Leaderboard and coins (leaderstats)

In many games you see a list with points at the top right. You build it with a folder called “leaderstats” – and coins to collect while you’re at it.

What you’ll learn

  • create leaderstats when a player joins
  • let players collect coins by touching them
  • prevent double counting with a lock

Create leaderstats

This Script goes into ServerScriptService. For every player who joins it creates a folder leaderstats with a number value Coins. Roblox then shows it in the player list automatically.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
  local leaderstats = Instance.new("Folder")
  leaderstats.Name = "leaderstats"   -- spell it exactly like this!
  leaderstats.Parent = player

  local coins = Instance.new("IntValue")
  coins.Name = "Coins"
  coins.Value = 0
  coins.Parent = leaderstats
end)

Collect coins

Build a yellow, anchored part as a coin and put this Script inside. The variable taken is a lock: without it one touch would count several times, because Touched fires very often in a row.

local coin = script.Parent
local Players = game:GetService("Players")
local taken = false

coin.Touched:Connect(function(hit)
  if taken then return end
  local player = Players:GetPlayerFromCharacter(hit.Parent)
  if player then
    taken = true
    player.leaderstats.Coins.Value += 1
    coin.Transparency = 1
    coin.CanTouch = false
    task.wait(5)   -- the coin comes back after 5 seconds
    coin.Transparency = 0
    coin.CanTouch = true
    taken = false
  end
end)

Keep it fair

Always change points in a Script (on the server), never in a LocalScript – otherwise cheaters could give themselves points. mahshid.de does exactly the same with stars: the server checks everything.

🛠️ Try it

Create leaderstats with “Coins” and place five coins in your obby. Bonus: a second value “Stage” that goes up at every checkpoint.

🧠 Mini quiz

What must the folder be called so Roblox shows the points in the player list?

What is the variable taken in the coin for?

Roblox and Roblox Studio are trademarks of the Roblox Corporation. mahshid.de is not affiliated with Roblox. All links to Roblox lead to the official sites.