Ad
Log in to vote
0

How to make script continue after function?

Asked by 9 months ago
Edited 9 months 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 9 months 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 — 9mo
Ad

Answer this question