Menu
CoddyTech

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 icon

Challenge

Medium

When a player joins, give them a scoreboard:

  1. a Folder named leaderstats inside the player
  2. an IntValue named Coins with the value 0
  3. an IntValue named Level with the value 1

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)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Roblox Game Scripting

Practice on your own: Online Lua compiler