So I’ve been working at this for a few hours now, and I just can’t figure out how to get the script to do a wait of 300 seconds while running other functions. Below is the basic layout of my script
local function clean()
--Code
end
local function two()
--Code
end
local function one()
--Code
wait(25)
two()
end
one()
wait(300)
clean()
You can use coroutines and other methods from the task library to handle yields while also executing other tasks.
--//Execute function after X seconds
task.delay(300, clean)
--//Execute function that has yield statements, prevent it from affecting main thread of execution
local function someAsyncFunction()
task.wait(3)
print'yay'
end
coroutine.wrap(someAsyncFunction)()
print'i run immediately yessir'
Sorry. More specifically, my problem is that the wait(300) does not even begin. I think it is due to the one() function having a wait in it as well, though I honestly have no clue.
The script just stops from progressing downwards after one() is called, though one() still carries out its function correctly and still fires two() properly
Add “return” to the end of two() and it should work the way you want it to. If for what ever reason this does not fix it, add a “return” to the very end of one() as well.
Others have pointed this out but… You could use a coroutine to accomplish this.
local function clean()
--Code
end
local function two()
--Code
end
local function one()
--Code
wait(25)
two()
end
local one_CR = coroutine.wrap(one) -- Doing this allows you to run `one_CR` multiple times
one_CR() -- one _ Co-Routine
wait(300)
clean()