So right now, I have around 15+ events in my game i.e. Spawn, TeamSelect, Buy, Sell, etc that are all handled in a single script. It’s around 800 lines of code. Would it affect performance? Would it better to make a separate script and evenly spread the events?
For example, when the round is about to start, around 50+ people fire the TeamSelect/Spawn event around the same time.
I’ve 100% noticed some latency.
If you noticed that there’s latency, the divide up the work with ModuleScripts. I use one single script to manage all events, but they are instantly handled by their respective ModuleScripts.
When it comes to “one main script” handling all the events I try to steer away as much as possible. Organizational wise it is a pain, but it also opens the potential for one small error to cause your entire coding infrastructure to come crashing down.
I typically split up events into different scripts, (i.e a script for transaction events, a script for teleporting events, etc), and handle anything more direct through ModuleScripts as @overflowed had suggested.
Latency is most likely caused as a result of wait times or something similar in your code somewhere along the lines, so worst case you could go through wrapping each function that the events are connected to.
The number of tasks defined in a single script should not be affecting performance. All code exists as data somewhere in memory.
The structure and implementation should be defining your programs efficiency.
Using module scripts, you can you memoization to reduce repetitive code.
The latency you’re experiencing is likely due to the implementation of your system. Instead of communicating from 50 clients to the server at once, find a method to communicate from server to client. That way instead of the server handling 50 RBXScriptSignals, each client handles 1.