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.

local playerstats = game.Players.LocalPlayer.leaderstats.Coins
local playerstats2 = game.Players.LocalPlayer.leaderstats.Clicks
local aneeded = 1000

function exchange()
    if playerstats2.Value >= aneeded then playerstats2.Value = playerstats2.Value - aneeded and playerstats.Value == playerstats.Value + 1
    end
end

script.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()

local 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