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

How can I force a function to run without waiting?

How do I continue a function that has wait()

local function Test1()
    print("function started")
    wait(1)
    print("function ended")
end

local function Test2()
	print("About to call function Test")
	Test1()
	print("All Done!")
end

Test2()

if I run this (untested) local-script , the script will first run function Test2() and then it will automatically run Test1() because it's in the Test2() function. The thing is , the print("All Done!") will not be in the output before 1 second later because Test1 has wait(1) in it.

Question : How can I print("All Done!") without waiting even though Test1() have wait(1) ?

1 comment

1

THAT'S THE ANSWER! should be in details though , but still thanks. I did a quick search on google about the spawn function and BOOM. Done.

1 answer

✓ Accepted answer

Don't use spawn.

Use coroutines. spawn uses a legacy scheduler and has a built in call to wait at the beginning.

Specifically, use coroutine.wrap. It creates a thread and returns a function you have to call to resume it.

coroutine.wrap(Test1)();

1 comment

0

spawn op

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