I’m not sure if this is possible, but how would I check if a variable like 1
changes instead of having to use an infinite loop.
local var = 1
local function onChange()
-- blah blah blah
end
-- how to run onChange when var changes
I’m not sure if this is possible, but how would I check if a variable like 1
changes instead of having to use an infinite loop.
local var = 1
local function onChange()
-- blah blah blah
end
-- how to run onChange when var changes
Just do:
if var == 1 then
print("Var variable hasn't changed!")
else
-- var variable has changed..
end
There are multiple ways to do it.
local var = 1
local function onChange()
-- blah blah blah
end
local function changeVar(newVar)
onChange()
var = newVar
end
changeVar(5)
Usually you want to add a line after the variable has changed(operation) instead of relying on events. This is however subjective to what sort of scripting architecture you’re looking for.
Yeah, I want to detect when It changes. I don’t want to detect what it changes to, I don’t wanna use an infinite loop to keep checking it
You can use GetPropertyChangedSignal(The value you need) if you are using a value object and property.
Yeah I’ll probably just create a Value object and use that. Thanks for your help
GetPropertyChangedSignal actually works for any property of any object, like a Part’s transparency.
Just some additional info that may help
I know. I’ll probably just use Value.Changed tho, thanks!