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

How do you make a script that runs functions without waiting for one of the functions to finish?

For example, you could have a line of code like this;

function example()
print("hi")
 wait(5)
end

example()

print("hi2")

It will run example which will print "hi", then wait 5 seconds. Then after the 5 seconds, it will print "hi2".

How do you make it so it will print"hi2" and hi at the same time without changing

the wait?

1 comment

1 answer

✓ Accepted answer

Coroutines! Coroutines will run your function and then the rest of the code, but not one after another. Here's your code with a coroutine:

function example()
	print("hi")
	wait(5)
end

coroutine.resume(coroutine.create(function() example() end))

print("hi2")

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