A lot of this involves the way you organize you game and code, but it is possible to do and not a very tedious process if you fully understand what you’re doing, and what changes you are making.
One thing people recommend doing to make for performant games is to have specific functions run on seperate context levels (i.e Server or Client), The Client is essentially the Players view of the game, while the actual game is taken care of by the Server, The Client should take clear of visuals like Particles, Graphical Interface, Tweenings, and Animations, while the Server should handle all the Important Calculations thats are nessecary for running your game like a Round System, Times, Currency, or DataStores.
If the Server is managing these items, it can slow down your game, as the Server is calulating and applying changes to something it shouldn’t which is using more resources, the Client will be a lot smoother, and faster to apply these changes, because they are not too important, you can tell the Client to make these calulations, and changes.
If you are trying to Send Data between Clients and the Server, or just trying to replicate an effect to all Players, you use RemoteEvents
.
If it comes to Sending Data using RemoteEvents
(allows you to send Data to the Client or Server), make sure you perform sanity checks to avoid any exploits from the Client, About every single Exploit will be executed from the Client, and RemoteEvents can allow Exploiters Access to the Server, so when performing specific tasks, always assume that the Client is false, and make sure the Data is correct.
For Example, .Touched
Events that are handled by the Client can be manipulated as any changes that are applied to Client objects will also apply for the Event on the Client, in essense exploiters can change the location of the object, and the event will adjust according to Client Changes, a simple fix to this problem would be to ensure that the Player is in the Correct Spot using the Server, Client Changes will not apply to the Server unless explicity told to, so any change to the part on the Client wont happen to the Server, making it an ideal place to do it.
The Optimization here that the client is in charge of the event, and what fires while the Server is in charge of what goes on in the Event, the Server is not in charge of detecting whether or not the Player has Touched the Part, but whether the RemoteEvent has fired, where it can then check to ensure that the Client’s Response is true, in many cases, this can also be used as an anti-exploit.
As for your Example, that can be done with CollectionService
. which allows you to Tag Objects, and to Apply Stuff with the Specific Tag, instead of having multiple threads run at a time to apply a single connection, you can instead use the Service, and one script to apply these for you, which is more efficient, and keeps your game more organized.
This isnt really the only Example of its usage, it can also be used for a variety of other things, it can also be used for Players who are maybe on a Specific Team, or Weapons that require a specific tuning to work properly, it is up to you how you want to use it
ModuleScripts
are intended help you Organize your Code, and if used correctly, can make for very neat, and awesome things, something often people do is create a “Library” of sorts to store Modules which allows them to easily find what they need, or for a Module to get what it needs.
They themselves dont really provide any Optimizations, they just allow you to store code and data in them, which can then be fired from a Script, However they can be useful for Optimization purposes.
Another thing you also keep take note is that, not everything you do will make the game performant, There are specific optimizations that you may have to sacrifice in order to secure your game properly to have everything together, and inproper usages of code, or Services can slow down your game, so you should always account for these circumstances when trying to improve stuff in your games.