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

LeaderBoard Problems? Entering an existing value

Asked by 5 years ago

[Help picture] https://ibb.co/KWypMXD

I am trying to put the value of Output says that Player isn't a valid member of PlayerStats.

This is the code:

game.Players.PlayerAdded:Connect(function(plr) local f = Instance.new("Folder", plr) f.Name = "leaderstats" local coins = Instance.new("IntValue", f) coins.Name = "Coins" coins.Value = game.Players.Player.PlayerStats.Coins.Value end)

Pls tell me where in the code is wrong and correct it

1
R u sure the output is not the opposite? "PlayerStats isn't a valid member of Player" NickAtNick 163 — 5y
0
Yah it should be like that starmaq 1290 — 5y
0
oh yh the output is the opposite Chrisogbeide11 0 — 5y

1 answer

Log in to vote
0
Answered by
starmaq 1290 Moderation Voter
5 years ago

Why are you doing game.Players.Player. That's where the problem is coming from, probarly because "Player" doesn't exist inside Players. You can simply avoid that easily, the PlayerAdded event has a very useful paramater, it's the player that just joined. That "plr" variable, that you wrote, you can use that instead. Also, you might not wanna use the second argument for Instance.new which is the parent, it is deprecated but it still works causing some preformence issues. So just set the parent in a line by itself.

game.Players.PlayerAdded:Connect(function(plr)  
    local f = Instance.new(“Folder”)  
    f.Parent = plr
    f.Name = “leaderstats”  
    local coins = Instance.new(“IntValue”)
    coins.Parent = f 
    coins.Name = “Coins”  
    coins.Value = plr.PlayerStats.Coins.Value  
end)
Ad

Answer this question