Will using a spawn function on something nested in a loop basically remove it from the loops thread?

So I want to know if I put a spawn function inside of a loop will the code inside the spawn function run on a seperate thread from the loop, sorry if this is a dumb question?

https://developer.roblox.com/en-us/api-reference/lua-docs/Roblox-Globals

There will be a delay that will be at least 29 milliseconds, but it can take longer. People say to avoid using spawn.

Alright thanks ill use coroutines instead then

Yes, spawn runs the callback function in a separate thread so your loop will run in a separate thread.

No I meant the spawn function is inside of the loop

for i = 5, 12 do
     spawn(function()
          print("test")
    end)
end

will the code inside the spawn function run on a seperate thread from the loop The answer is yes.

spawn(function() --> calls the callBack in a separate thread or a new thread
      print("a") 
end)

Yes that’ll run in new threads.

Even though you didn’t ask, you should stay away from spawn.

Alright thanks for the information

1 Like

I know this is an old thread, but putting a spawn function inside of a loop doesn’t work anymore, at least according to me.

Coroutines work though.

does task.spawn() work though? and why is it not mentioned here