local function Num2()
wait(9999)
end
local function Num1()
print("A")
Num2()
print("B")
end
So when i do function Num1 it will do function Num2 and i want it to do print(“B”) and don’t wait for Num2 function to end. How can i make it don’t wait for Num2?
you can’t say that a coroutine is a better alternative to spawn when in the end they are the same. spawn is used when time is not critical, as in the case of managing the logic of a game.
coroutines should only be used when parallelism is required and the logic is complex enough. This is not the case.
There were several people talking about why using coroutines over spawn, one of the reasons is because spawn has a hidden wait function which makes it delay.
Not really micro-optimizations at all, there was also another post talking about why you should avoid wait() which is used in the spawn function. (Note, its not talking about things like wait(2) but just wait() )
In truth, two tasks, whether in a different script or “thread”, will not run exactly parallel to each other. Coroutines and spawns basically have no differences other than the fact that the spawn function has an implicit wait, since it has to wait about 30 milliseconds to start since it’s being queued in the task scheduler. Coroutines start instantaneously and you can create them, put them on hold, and start it later as opposed to spawn.
Coroutines generally are the better alternative; spawn even coroutines to work. In this case, it wouldn’t matter which to use since the OP doesn’t seem to be concerned about time
I am aware of the difference between coroutine and spawn because I read the manual. But I do not agree that coroutines are a better alternative because, otherwise, spawn would have already been discontinued.
The real power of a coroutine is not that it executes immediately, but rather the fact that they are pieces of code that can be resumed or suspended, allowing complex problems to be solved more easily