How do I use spawn (function()) and what does it do?

Due to spawn() not being on the DevHub that I could find, I have 0 clue what it means. I have a guess that it makes whatever is in the function reset every time a player respawns, but I am not positive. Can someone tell me how it works?

I just used it here

it spawns a new thread, so you could have stuff like

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

while true do
    wait(2)
    print("2")
end

and they would both run together

Oh I see. So that way instead of waiting for 1 function or loop to run, they both start at the same time?

Yeah,

take a look at Coroutines

1 Like

spawn is a Roblox method that starts a new thread, but it begins on the next step. It has its down sides, however.

2 Likes

spawn is a way to create a new thread. But the use of spawn is advised against.
I’d recommend coroutines for this instead.

4 Likes