So lets say I had a script:
local function a() wait(math.random(1,5)) print("This is a function") end) while true do a() wait() end
With this script, it would wait until our function, a
, is complete before running it again. Is there any way that I could make the while loop "ignore" the wait inside the function, and do the next thing immediately?
Yes, you use the coroutine.wrap
method to do this!
local function a() wait(math.random(1,5)) print("This is a function!"); end while true do coroutine.wrap(a)() wait() end