#How to cancel functions

1 messages · Page 1 of 1 (latest)

hybrid bluff
#

So I tried using :Disconnect() but they arent connections so they dont work and I've tried using other things like task.cancel() and some others but they dont work cuz functions are not threads. I just cant do it anymore im losing hope

hybrid bluff
#

I want to cancel it using another function

#

@olive iris

olive iris
hybrid bluff
#

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*

rare vessel
#

return

rare vessel
olive iris
rare vessel
hybrid bluff
#

I didnt

hybrid bluff
#

Can I use return outside a function using another function

rare vessel
#

like in a function, when you call return it just stops

rare vessel
hybrid bluff
#

But im using a for loop to cancel all the functions

rare vessel
#

as long as it is in a function it will work

rare vessel
#

and in the functions detect when that variable is true

#

then break

hybrid bluff
#
Plant:GetAttributeChangedSignal("TimeInterval"):Connect(function()
    for i,v in pairs(Connections) do
        v:Disconnect() -- Doesnt work just ignore
        table.remove(Connections,v)
     end
end)
hybrid bluff
#

That could work

#

lemme try it

#

Wait break?

rare vessel
#

I mean return

#

mb

hybrid bluff
#

Isnt it supposed to be return

rare vessel
hybrid bluff
#

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()

rare vessel
#

why would you return then?

hybrid bluff
#

To cancel the function?

rare vessel
#

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)

olive iris
#

Why would you even need to cancel a function though

rare vessel
#

to prevent the timer from affecting other things

rare vessel
#

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

hybrid bluff
#

So uh

rare vessel
#

bc it returns to the spawned function and not the one you want

hybrid bluff
#

Im cancelling the task.wait() because the wait time that the task.wait() is waiting is changed

#

Is that confusing

rare vessel
hybrid bluff
#

YEa

#

Yea*

rare vessel
#

that wouldnt work

hybrid bluff
#

Thats why im cancelling the function

#

I think I found a solution in dev forums