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

How to fix "leaderstats" not a member of player?

Asked by 5 years ago

I think I typed this right. But i keep getting a annoying error in the output. "leaderstats is not a valid member of player" even though it is a valid member of player.

01local playerstats = game.Players.LocalPlayer.leaderstats.Coins
02local playerstats2 = game.Players.LocalPlayer.leaderstats.Clicks
03local aneeded = 1000
04 
05function exchange()
06    if playerstats2.Value >= aneeded then playerstats2.Value = playerstats2.Value - aneeded and playerstats.Value == playerstats.Value + 1
07    end
08end
09 
10script.Parent.MouseButton1Click:Connect(exchange)
0
maybe a game.Players.LocalPlayer.leaderstats:WaitForChild("Coins") Before the rest of the code may work Fad99 286 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

That sometimes happen because the script is replicated some miliseconds before the leaderstats and then it does not find it, the way you can fix it is using :WaitForChild()

1local playerstats = game.Players.LocalPlayer:WaitForChild("leaderstats").Coins

does not need to do that for the second variable since it will only execute the rest when leaderstats was detected.

0
it then says "Coins is not a valid member of IntValue" XEpicGoldenBoyX 35 — 5y
Ad

Answer this question