So i know that a thread is and that adding a new script to a game can be considered like creating a new thread so when it comes to developing a game would it be better to organize my code into one local and one server script that then access several module scripts much like a class would with the local and server scripts executing several things at once using methods like coroutines and spawn() or have several local and server scripts that all do a set thing?
✓ ANSWER ACCEPTED
help with threads?
1 answer
✓ Accepted answer
In general:
- Code on fewer coroutines will be faster
- Code on more coroutines is easier to write (at least at first blush)
Coroutines are not threads.
Coroutines work with a scheduler to determine who-works-when. Only one coroutine works at a time, and switching between them takes a bit of time. That's why code with many different scripts / spawned coroutines gets slow.
Having multiple scripts is not a problem. 2 or 3 or 10 shouldn't be bad at all.
What you might want to avoid is situations where you have many copies of the same script, e.g., each one running one NPC / vehicle / turret / etc.
See here for both versions of code -- with spawn and without
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
ok thank you this helped a lot