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

What does spawn() function do and how do I use it?

I looked here spawn() function and it doesn't give a lot of information, can someone give an example on how to use it/how it works and what it does?

1 comment

0

spawn(f) schedules a new thread with body function f

1 answer

✓ Accepted answer

A basic way to put it, its an updated coroutine. I use them as basic code jumps where i can execute something at the same time.

Dont use to many of these; it can actually create lag.

So a basic example:

while true do
	wait()
	print'1'
end

print'2'

So in normal terms the print'2' will never be executed but...

spawn(function()
	while true do
		wait()
		print'1'
	end
end)

print'2'

if we do it like above the console will look somewhat like this...

--> 1 --> 2 --> 1 --> 1 --> etc

If you have any more questions let me know in the comments and i will get back with you asap

3 comments

0

So spawn() basically allows 2 things to be ran at once.

0

No. No 2 things can be run at the exact same time.

0

So it probably has as much purpose as do while loops

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