Leaderstats
Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 13 of 24.
The scoreboard in the top right corner of a Roblox game is made from a folder named leaderstats inside each player. Every number value in that folder becomes a column.
Players join after the game starts, so you make the folder when the Players service fires PlayerAdded:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local gems = Instance.new("IntValue")
gems.Name = "Gems"
gems.Value = 5
gems.Parent = leaderstats
end)game:GetService("Players") gets the Players service. An IntValue holds a whole number in its Value property, and its Name is the column title. The folder name must be exactly leaderstats, all lower case, or the scoreboard ignores it.
Challenge
MediumWhen a player joins, give them a scoreboard:
- a
Foldernamedleaderstatsinside the player - an
IntValuenamedCoinswith the value0 - an
IntValuenamedLevelwith the value1
Press Play to see the scoreboard, then Check.
Try it yourself
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
print(player.Name .. " joined")
-- 1. A Folder named leaderstats inside the player
-- 2. An IntValue named Coins, starting at 0
-- 3. An IntValue named Level, starting at 1
end)
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Roblox Game Scripting
2Loops and Functions
Row of PillarsStaircase BuilderTower BuilderCoin FactoryBlinking LightVanishing Bridge5Your First Game
Your First ObbyPractice on your own: Online Lua compiler