Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
itpres 5
10 years ago

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

Log in to vote
1
Answered by
Dummiez 360 Moderation Voter
10 years ago

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)

Ad

Answer this question