Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to check when number value changes?

Asked by
asadefa 55
5 years ago
Edited 5 years ago

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?

0
there's no way but what you can do is just call a function when you change it HappyTimIsHim 652 — 5y
0
Don't forget to accept my answer if it helps out. User#24403 69 — 5y

2 answers

Log in to vote
3
Answered by 5 years ago
Edited 5 years ago

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.

Ad
Log in to vote
0
Answered by
asadefa 55
5 years ago

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

0
Yes, if my answer helps out please accept it. It gives us both reputation that we deserve. User#24403 69 — 5y

Answer this question