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 4 years ago
Edited 4 years ago

So lets say I had a script:

1local function a()
2    wait(math.random(1,5))
3    print("This is a function")
4end)
5 
6while true do
7    a()
8    wait()
9end

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 4 years ago

Yes, you use the coroutine.wrap method to do this!

1local function a()
2    wait(math.random(1,5))
3    print("This is a function!");
4end
5 
6while true do
7    coroutine.wrap(a)()
8    wait()
9end
0
It appears to have worked! Tysm! NickIsANuke 217 — 4y
Ad

Answer this question