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

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

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)

1 comment

0

maybe a game.Players.LocalPlayer.leaderstats:WaitForChild("Coins") Before the rest of the code may work

1 answer

✓ Accepted answer

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.

1 comment

0

it then says "Coins is not a valid member of IntValue"

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