#How to cancel functions
1 messages · Page 1 of 1 (latest)
break or return
Show code example
kk
WaitConnection = function(TimeInterval)
table.insert(Connections,WaitConnection)
task.wait(TimeInterval)
end
So this is the function
and basically whenever I use a wait function
I use that instead
But when a value changes I want to disable all the functions
cancel*
return
break is for loops, not functions
Maybe he used a loop?
dosent look like it here tho
I didnt
like in a function, when you call return it just stops
it has to be in a function
But im using a for loop to cancel all the functions
as long as it is in a function it will work
then I would instead make a variable
and in the functions detect when that variable is true
then break
Plant:GetAttributeChangedSignal("TimeInterval"):Connect(function()
for i,v in pairs(Connections) do
v:Disconnect() -- Doesnt work just ignore
table.remove(Connections,v)
end
end)
Isnt it supposed to be return
yeah ur right
How will I detect when the variable changes though?
Its not a loop
and it fires only once
and the code inside it is only a task.wait()
why would you return then?
To cancel the function?
I mean you can just not preform the stuff in the function after the timer if the variable is tru
you can also use task.spawn(function)
Why would you even need to cancel a function though
to prevent the timer from affecting other things
to prevent other things from running that you dont want
like if I wanted to make a function that scales everyones head. If I only wanted a few or wanna stop it somehow midway I would use return
btw return dosent work in task.spawn
So uh
bc it returns to the spawned function and not the one you want
Im cancelling the task.wait() because the wait time that the task.wait() is waiting is changed
Is that confusing
like you change the time while its waiting?
that wouldnt work