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

Leaderboard shows for everyone except first player. How can I fix this?

My Leaderboard script displays a leaderboard for every player in the game, except the first player that joins. How can I fix this?

function playerAdded(plr)

   local stats = Instance.new("IntValue", plr)
   stats.Name = "leaderstats"

   local KOs = Instance.new("IntValue", stats)
   KOs.Name = "Kills"
   KOs.Value = 0
   
   local WOs = Instance.new("IntValue", stats)
   WOs.Name = "Deaths"
   WOs.Value = 0
   
   local Money = Instance.new("IntValue", stats)
   Money.Name = "Bronze"
   Money.Value = 0

   local XP = Instance.new("IntValue", stats)
   XP.Name = "XP"
   XP.Value = 0


end

game.Players.PlayerAdded:connect(playerAdded)


1 answer

✓ Accepted answer

It might have been declared before the player could actually join. Try adding this line to make sure that your character is in the game. repeat wait() until plr.Character

function playerAdded(plr)
	   repeat wait() until plr.Character
	   local stats = Instance.new("IntValue", plr)
	   stats.Name = "leaderstats"
	
	   local KOs = Instance.new("IntValue", stats)
	   KOs.Name = "Kills"
	   KOs.Value = 0
	
	   local WOs = Instance.new("IntValue", stats)
	   WOs.Name = "Deaths"
	   WOs.Value = 0
	
	   local Money = Instance.new("IntValue", stats)
	   Money.Name = "Bronze"
	   Money.Value = 0
	
	   local XP = Instance.new("IntValue", stats)
	   XP.Name = "XP"
	   XP.Value = 0
end

game.Players.PlayerAdded:connect(playerAdded)

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