Leaderstats
Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 13 of 25.
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
MediumGive every player a scoreboard when they join.
- In
PlayerAdded, make aFoldernamedleaderstatsinside the player. - In the folder, add an
IntValuenamedCoinswith the value0. - Add another
IntValuenamedLevelwith the value1.
Press Play: the scoreboard shows Coins 0 and Level 1. 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)
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