Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with a leaderboard?

game.Workspace.PlayerAdded(function(player)
	local stats = Instance.new("IntValue", player)
	stats.Name = "leaderstats"
	
	local points = Instance.new("IntValue", player.leaderstats)
	points.Name = "Points"
	
	local wins = Instance.new("IntValue", player.leaderstats)
	wins.Name = "Wins"
	
	
end)

What in the world is the problem? Basically, what the script does is load an IntValue and creates a leaderboard. It's not working, but I don't receive an error about WHY it doesn't work.

2 answers

✓ Accepted answer

You haven't initialized leaderstats, and you're calling PlayerAdded on the wrong service. Your code should look like this:

game.Players.PlayerAdded:connect(function(player)
	--PlayerAdded is for game.Players, not game.Workspace.

	 --Initialize the leaderstats model in the player
	local leaderstats = Instance.new("Model", player)
	leaderstats.Name = "leaderstats"

	--Initialize a leaderboard value
	local pts = Instance.new("IntValue", leaderstats)
	pts.Name = "Points"
	pts.Value = "0" --Set default value, data persistence overrides this.
end

PlayerAdded isn't associated with Workspace, but with the Players service instead. I don't believe parenting stats to the character would display them on the leaderboard.

This discussion is preserved as it was. New answers, comments, and votes are closed.