Im trying to make a script that changes the value to 0 if it is a negative number, However, It isn’t working, the value still remains negative after I change it through the explorer.
I tried finding solutions in the DevForum but I didn’t find any
Heres a shortened version of my code:
local char = script.Parent
local CHealth = Instance.new("IntValue", char)
CHealth.Name = "CHealth"
CHealth.Value = 100
CHealth.Changed:Connect(function()
if CHealth.Value < 0 then
CHealth.Value = 0
end
end)
The script is a server script and the parent of the script is StarterCharacterScripts
Your event here will be triggered if the change has happend through any remote that communicates with the server and client, or just on the server and stuff that would change it for everyone.
Exactly, meaning it will only detect when it changes on the server. Can you confirm that you’re changing the value on the server instead of on the client?
In case you’re still not following, go into a Studio play session. In the test column, click on Current: Client. Direct to the Character and change the value from there. You’ll notice that it changes as it’s a ServerScript, not a LocalScript. Because it’s a ServerScript, it doesn’t care about changes on the client. It only cares about changes on the server.
I know, I tested your code on the server, and it worked perfectly. You could change this through a remote aswell [ from client to server]. And it would work aswell .
Oh, you’re right, It changed on the server
Im just curious now, if I copy and paste that code on a local script(and do a change or two), will it change on the client too?