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

Value not updating properly?

I have this script inside a part that is supposed to give you 5 coins every time you touched it, which works well enough, but when I set my coins to a different number, say, it was at 30, and I set it to 14, when I pressed the part again it would add 5 to my old value of 30 for some reason, can anybody point out why this script doesn't work?

script.Parent.MouseClick:Connect(function(player)
	local coins = player.leaderstats.coins
	coins.Value = coins.Value + 5
end)

3 answers

✓ Accepted answer

That's because you change the value from the client-side, which does not update the server, the server still sees the value as 30, so what you need to do is just update the value from the server using a script and it should work fine, there is nothing wrong with your current script

Hope I helped, please let me know if you have further questions!

Try setting it to 14 on the server instead of the client. The reason is that the client only changes how things look on their side, not the server's side, which is where I assume the script is running from. The server stills sees 30, as well as everyone else on the server.

The automatic parameter of Mouse-click is the mouse, so it would think the player is the mouse.

So you need to define the player.

Remember keep scripting ;)

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