The treasure — coins and a real score.
Two scripts, two places, one system. This is how real games are wired together.
Touch a coin → it vanishes → your score goes up on the actual leaderboard in the corner of the screen.
One script builds the scoreboard. Another pays into it.
Until now, one script did one job. Real games are systems — separate scripts in separate places that depend on each other. Today's pair: a scoreboard builder that runs when a player joins, and a coin that finds that scoreboard and adds to it.
Script 1 — the scoreboard (ServerScriptService).
In Explorer: ServerScriptService → + → Script. Name it Leaderboard.
Type:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats
end)Roblox has a built-in rule: any folder named exactly leaderstats — lowercase, no spaces — inside a player automatically shows on the leaderboard. Spell it exactly or nothing appears.
Script 2 — the coin (inside a Part).
Insert a new Part. Properties: BrickColor Bright yellow, Material Neon, and check Anchored so it doesn't fall.
Name it Coin and add a Script inside it:
local coin = script.Parent
local reward = 10
local collected = false
coin.Touched:Connect(function(hit)
if collected then return end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
collected = true
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
if coins then
coins.Value = coins.Value + reward
end
end
coin:Destroy()
end
end)Play. Touch the coin. Watch the top-right: Coins: 10.
The tools you just unlocked.
Creates objects from code instead of clicking. Folder, IntValue, even Parts — you can build anything this way, while the game runs.
Stricter than the Humanoid check: it only says yes for actual players, never NPCs. Coins should pay people, not zombies.
Deletes the coin from the game. Gone. That's also a debounce — a destroyed coin can't be touched twice (the `collected` flag covers the tiny window before it vanishes).
Find leaderstats, then find Coins, then add. Each step confirms the thing exists before using it. This habit is the whole difference between working code and crashing code.
Duplicate the coin (Ctrl+D) five times and scatter them. Make one worth 50 by changing `reward` — and make that one bigger and a different color so players can tell it's special.
The Repair Shop.
🔧 The leaderboard doesn't show up
The folder must be named exactly leaderstats — all lowercase, no spaces. It's a magic name.
The Leaderboard script must be in ServerScriptService, not inside a part.
Were you already in Play mode when you added it? PlayerAdded only fires when a player joins — Stop and press Play again.
🔧 The coin falls through the floor or flies away
Check Anchored in the coin's Properties.
🔧 The coin vanishes but the score doesn't change
Check both spellings match across the two scripts: leaderstats and Coins. FindFirstChild searches by exact name.
Script 1 builds a thing in a known place with a known name; Script 2 finds it by that name. That's system design, miniature edition.
leaderstats, then Coins, then add. Nil-checks at every step — the crash-proof habit.
+150 XP. You have an economy. Mission 5 adds physics.