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

When I check for the amount of money a thing cost in the shop, it gives me this error?

Hello there. I'm making a shop system and when I do a if stament to see if the player has enough money to buy the item it gives me this error.

workspace.Apple.Script:2: attempt to index nil with "leaderstats"

Here's the code I'm using

script.Parent.ClickDetector.MouseClick:Connect(function()
	if game.Players.LocalPlayer.leaderstats.Money.Value >= 3 then -- heres the part im talking about
		game.Players.LocalPlayer.leaderstats.Money.Value =  game.Players.LocalPlayer.leaderstats.Money.Value - 3 -- dont worry its just the text doing that
	end
end)

also this for somereason

game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value - 3 -- sorry, the text did that

2 comments

0

Are you running the code in a LocalScript or a Script?

0

a script

3 answers

✓ Accepted answer

LocalPlayer doesn't exist on the server so it's returning nil (hence the error). The MouseClick event has a parameter which is the player that clicked it, use that instead.

2 comments

0

i don't understand...

0

Which part do you not understand?

Try using :FindFirstChild('leaderstats') or :WaitForChild('leaderstats') Maybe that'll work.

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