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

How do I use spawn()?

The wiki says:

Executes function f after thread next yields. The function f is called with 2 arguments: The elapsed time and the current place time.

But I don't really know what that means, could someone explain this in more layman terms? Or maybe give an example?

2 answers

Here is a good example of how it works:-

function test(del,placeTime)
	print("Thread ran ")
end

print("Start")
spawn(test)
print("Stop")
wait()

So you should expect to see the output:-

start

Thread ran

Stop

But the output is:-

Start

Stop

Thread ran

This is because it will run "after thread next yields"

What does this mean

"Yield" definition "give way to arguments" (from google).

Summery

The thread will only be created after the next wait is ran, The wait time is not included so changing this will not delay the thread.

As for the two agreements they are rarely used but as far as I can tell you cannot pass arguments within the spawn function.

Hope this helps

3 comments

0

How would this be useful when making a game?

1
1

Not the best explanation but I learned something. Good job :3

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