Script not applying numbers to Value

I’m trying to make a script where once you click on a SurfaceGui, a Value located in the workspace has it’s value changed.

function SCRAM()
	workspace["SCRAM?"].Value = math.random(1,2)
script.Disabled = true
end

script.Parent.Coolant.One.MouseButton1Click:Connect(SCRAM)

Everything so far is correct just except this and when I check the workspace, the value has not been added.
Anybody know the solution to this?

Hello, you need to use a Remote Event, to fire the value over to the server. Changing it on the client won’t work. What you can do is fire over your math.random result and then on the server pick that up and change the value to it.

1 Like

Could be abusable on the client, but I don’t know man, maybe do the math.random on the server?

No need to worry guys. I simply had to duplicate this:
workspace[“SCRAM?”].Value = workspace[“SCRAM?”].Value = math.random(1,2)
Thanks for your ideas!

Transfer the SCRAM() function to a serverscript, and make a remote event. Once the button get’s clicked, you fire the remote event and the server will handle the rest. Make sure to remove the script.Disabled = true line. It would look like this:

script.Parent.Coolant.One.MouseButton1Click:Connect(function()
      game.ReplicatedStorage.RemoteEvent:FireServer()
      script.Disabled = true
end)

then on the server, you do this:

Game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)
     workspace["SCRAM?"].Value = math.random(1,2)
end)

I hope this helped you!