IntValues Not Updating?

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 :slight_smile:

1 Like

Are you manually changing the value of CHealth on the Client, or on the Server?

For me it works, change it on the server. I think you might have done this from the client, hence it didnt work for you.

–If you change that on the client :

it won’t change anything on the server :

if you change that on the server:

everyone would see this,

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.

The Script I am using is a Server Script, Not a local one

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.

1 Like

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?

If you do that code on a local client, you’d need to use a remote to fire this to the server, and then from the server, you’d do all of that.

1 Like

alright, thank you, I’ll mark a solution on this topic now.

Thank you, it’s the green checkmark tho.

Best of luck!