Hello everyone! So I’ve recently been trying to change a Number value with a Mouse click but its not working and I honestly have no idea why. Here’s the script:
local Players = game:GetService(“Players”);
local Player = Players.LocalPlayer;
local Mouse = Player:GetMouse();
local val = game.ReplicatedStorage.NumberValue.Value
The reason this is happening is because when you access the value and store it in a variable the value stored at that address will remain the same.
So when you are storing the value and if the value is 0 every time you increment the value 1 will be added to 0 and thus it will not get incremented to the current value but the value stored in that variable which is 0, resulting in 0 + 1 = 1.
In that case access the value the moment you are changing it. In the function scope.
The solution provided by @Boustifail would work.