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

How to check when number value changes?

I try this:

local number = 0

number.Changed:Connect(function() --error

end)

It doesn't work. Constantly checking via while true is inefficient. How to call an event when a number variable changes? Or can I?

2 comments

0

there's no way but what you can do is just call a function when you change it

0

Don't forget to accept my answer if it helps out.

2 answers

✓ Accepted answer

That will not work. What you can use is a NumberValue or an IntValue and do something when it changes.

local intValue = game:GetService("ReplicatedStorage").someIntValue -- # some int value 

intValue.Changed:Connect(function(newValue)
    -- # ...
end)

The changed event on ValueBase instances is modified to fire only on the Value property, so you will not need to worry about any :GetPropertyChangedSignal()'s or anything. newValue will be the new value.

Just in whatever event that would change the int value, also insert the code to do whatever it is to be done when the value changes

1 comment

0

Yes, if my answer helps out please accept it. It gives us both reputation that we deserve.

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