myIntValue.Changed:Connect(function(newVal)
if newVal >= 25 then
...
end
end)
according to Google Analytics this is occasionally throwing the error “attempt to compare nil and number.” I’m like 99% sure I never set the value to nil in any script. So can .Changed fire with nil?
.Changed fires when ANY property of the Instance changes. To get an event that is fired ONLY when the Value property is changed Edit: My bad, I got this wrong, credit to @sjr04 and @iiFusionzX for pointing this out. You can use .Changed, and you could also use :GetPropertyChangedSignal()
What you could do is add a check to ensure that the new value is not nil if you are using the .Changed event.
You could use :GetPropertyChangedSignal("Value"):Connect(...), like so:
function UpdatedValue()
local newVal = myIntValue.Value
if newVal >= 25 then
...
end
end
myIntValue:GetPropertyChangedSignal("Value"):Connect(UpdatedValue)
Incorrect, ValueBase instances (IntValue, BoolValue, etc) use a non-inherited Changed event which fires only on the Value property changing. Instead of the classic “string property name being passed” as an argument to the listeners, the behavior is that the new Value is passed to the listener
Is there a way to listen for a number being changed? My code is in a local script and currentExp gets its value from an IntValue that is called from the server script, which is then sent back to my local script
I get the error " attempt to index number with ‘GetPropertyChangedSignal’" when I used GetProperty and “attempt to index number with ‘Changed’” when I use .Changed