I have a folder in ServerStorage called ModuleScripts and inside of that folder there are several module scripts. Most of those module scripts contain one function that is returned. Should I be putting all the functions into one module script? Will that work more efficiently? I know that this might sound like an opinion based question but it is not. What is the most effective, efficient, and easily manipulated way to organize my functions? Thanks!
Should I be putting my many functions inside module scripts all into one module script?
1 answer
It all really depends. Personally, I like to have every ModuleScript have just a single purpose, and return a single function. It makes any bugs or issues very clear and keeps things organized overall.
Let's say we have a few related functions, however; say you have a function named CreatePartInColor which creates a new Part instance and sets it to a specified colour. Then you have another function named CreatePartInRainbow which does the same thing but the colour constantly changes rather than staying at a specific colour. In this case, you could debate that keeping both these functions in a single module and returning the table of all functions is a better option because they have similar purposes.
It really does come down to your preference in structure and organization, but if you really are looking to see if combining all the scripts into one would give your game a performance boost - I really doubt it. Sure, each ModuleScript is run once if they're require()d from a server but combining two scripts should take extremely little - if not no - additional processing power, because you are essentially asking the computer to follow the same instructions, but instead of sectioning your instructions you are lining them up all at once.
So, if you want to be able to easily identify issues, add new content or modify existing work, I would highly recommend keeping a single purpose for every ModuleScript, unless the modules are all very related - or if you are using OOP (object oriented programming) and are creating a class, in which case I would have most or all of my methods in that module.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
What is the purpose of these functions within the ModuleScripts?