Menu
CoddyTech

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 icon

Challenge

Medium

Give every player a scoreboard when they join.

  1. In PlayerAdded, make a Folder named leaderstats inside the player.
  2. In the folder, add an IntValue named Coins with the value 0.
  3. Add another IntValue named Level with the value 1.

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

Practice on your own: Online Lua compiler