Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make script continue after function?

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

✓ Accepted answer

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

1 comment

0

It appears to have worked! Tysm!

This discussion is preserved as it was. New answers, comments, and votes are closed.