In a game I am working on, I used that task.spawn() function to speed up the setting up and booting up of some tycoons. Before using task.spawn(), they all tended to boot up linearly, and that would take 1-3 minutes when the server first boots up - not super ideal.
So I started using task.spawn() to speed that process up - and it worked! Except that sometimes, one or two out of the 16 or so tycoons would not be set up right.
I thought this was something with the tycoon kit I was using, but then I discovered the error in the script that set them all up. Apparently, for the last one or two tycoons, it appears that any code within the task.spawn would not be executed after task.spawn() was called about 16 times within a very short period of time (within a for loop). I cut this down to calling it 8 times within the same period, and so far, no new reports about the issue.
This was an extremely rare glitch in the game but it was still a glitch, nonetheless.
Is it possible that task.spawn() or any of the other task schedulers can be called too many times in a certain time period, and will they time out and ignore the code within them?
1 Like
What are you doing that takes multiple minutes to boot up? Thatâs insane. And itâs worrying that whatever youâre doing has inconsistent behavior.
I canât exactly answer your question, but:
If task.spawn
truly sped up the process, then itâs most definitely an issue with the tycoon kit youâre using; that kind of improvement only comes if the script to boot the tycoons has any yielding in it. task.spawn
is still âlinearâ â otherwise known as single-threaded; if you want multiple tasks to truly run at the same time, I suggest looking into parallel Luau, itâs pretty wild stuff.
1 Like
Thereâs a funny âyes and noâ answer to this thread - as in, no itâs not possible to pseudothread with the task library too much, but yes itâs also possible. The difference in those is between an actual limitation and a code-related issue (e.g. bad practice on your part).
As some of the above posts mention, if using task.spawn is supposedly speeding up the setup of your tycoons, this isnât an issue of scheduling but rather that your setups are yielding too much. You should only ever yield when itâs appropriate to do so or is an unavoidable part of whatever functions youâre calling. Relying on spawn to speed up your setup is a code smell.
There shouldnât be any reason why your tycoons are taking even the minimum amount of time you specified in your range, that being 1 minute. They should be ready the moment clients are able to connect into the server. I do advise you to perform a deeper investigation on your code.
This isnât a problem that Parallel Luau would resolve, nor would be needed for. Thatâs an overkill solution. The root problem should be addressed which is too much yielding.
1 Like