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

Why doesn't this script work? [answered]

Asked by 9 years ago

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

0
No error? Redbullusa 1580 — 9y
0
Oop. There is: "Localplayer is not a valid member of Players" DrCylonide 158 — 9y
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 Redbullusa 1580 — 9y

2 answers

Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
9 years ago

I think the Error came from line 4 should be

game.Players.LocalPlayer.leaderstats.Money.Value

0
Thanks! I don't know why I didn't catch that earlier. DrCylonide 158 — 9y
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"]). Redbullusa 1580 — 9y
Ad
Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
9 years ago
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).

Answer this question