Are spawn functions laggy?

Hello everyone , not much to ask here. Are spawn functions laggy? Lets say in every script I have 2 spawn functions to allow code to run simultaneously, is this laggy? do I have to break the spawn? (all I have in spawns usually are wait() )

1 Like

spawn is really bad to use, instead use coroutine

It is not laggy at all. I am pretty sure.

what makes spawn so bad to use?

Spawn isnt bad, I do not see how coroutines spawn someone better.

It is not bad and not laggy, spawns is good for your games!

Spawns are more outdated, there are a lot of topics about how bad it is to use spawn or delay

1 Like

isnt their a yeild before a spawn function?

Hm, really? How comes mine work perfectly fine

spawn() gives a delay to your function, I suggest you completely AVOID using spawn() and use this instead

    -- do something
1 Like

is coroutine just as easy to use as spawn, also that means i have to replace all my scripts with spawn with coroutine oof

oh? and that provides the same result as running code simultaneously? that’s easier than i thought thank you!

Please mark rokoblox5 has the solution if he helped you.

1 Like

Since spawn() has a built-in wait() a lot could go wrong in the process, I personally use coroutines as they have no built-in delays.

In general, you should avoid Debris:AddItem(), spawn() and other functions that has a delay added to them.

Debris does not yield the current thread, does not require a new thread and will not error if the object is already destroyed. For this reason it is the recommended method for cleaning up objects with a fixed lifetime.

local debris = game:GetService("Debris")
local averageTime = 0

for i = 1, 10 do
    local parts = {}
    for i = 1, 250 do
	    table.insert(parts,"Part", game.Workspace))

    local startTime = os.clock()
    for _, part in pairs(parts) do
	    debris:AddItem(part, 5)
    local endTime = os.clock()

    averageTime += (endTime - startTime)
    print(endTime - startTime)

print(averageTime / 10)

The average time upon running the Debris part of this function was 0.15ms, with the max being 0.18ms. Debris does not yield the thread.

Debris is :Destroy() with a delay, it is the same, except for the built-in delay Debris has.
And, I never said that Debris yields the current thread, because it doesn’t.

Here’s why I use :Destroy() over :AddItem().

task.spawn() doesn’t give a delay any longer to the function, u still think coroutines are better?

1 Like

This is an old post dude. I believe this was before they added a task library, 2 years ago btw.

1 Like