Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make script continue after function?

Asked by 3 years ago
Edited 3 years ago

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?

1 answer

Log in to vote
3
Answered by 3 years ago

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
0
It appears to have worked! Tysm! NickIsANuke 217 — 3y
Ad

Answer this question