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

Why doesn't this script work? [answered]

Here is my script:

It is supposed to add eight (8) "money" to the player who clicked the image GUI. It is in a localscript.

local image = script.Parent

image.MouseButton1Down:connect(function()
	game.Players.Localplayer.leaderstats["Money"].Value = game.Players.Localplayer.leaderstats["Money"].Value + 8
end)

Nothing happens when I click on the GUI. What is wrong?

Thank you

3 comments

0

No error?

0

Oop. There is: "Localplayer is not a valid member of Players"

0

You shouldn't worry too much about the format of the name (leaderstats["Money"]), because that is logically valid. Check the 4th bullet. http://wiki.roblox.com/index.php?title=API:Class/Instance/Name

2 answers

✓ Accepted answer

I think the Error came from line 4 should be

game.Players.LocalPlayer.leaderstats.Money.Value

2 comments

0

Thanks! I don't know why I didn't catch that earlier.

0

leaderstats["Money"] is still valid, despite of its irregular format. This is ideally used for names with spaces in them (leaderstats["WIPE OUTS"]) or with numbers at the beginning of a name (leaderstats["1337"]).

game.Players.Localplayer

should be

game.Players.LocalPlayer

The reason for this is is because scripts are case-sensitive, and respond to exact key words. If it's misspelled or capitalized incorrectly, scripts will try and do what you told them to do, but it might not reach the same result as intended. In this case, it was finding the player.

Also, check and make sure that your "Money" value is an int value (or a number value, if "Money" has decimal places less than 1).

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