Help with scripts understanding

I’ve been wondering, how many scripts should a decently-sized game have, and when would I use modules over local scripts/server scripts?
I know that using module scripts is useful for code readability and scalability, but would that mean that the best thing to do is use modules for everything?
Would love a detailed explanation.

all game vary in script amounts. an obby game would have very little, while an fps would have a lot.
there really isnt a reason to worry about the number of scripts, as long as you make sure you arent repeating code in different scripts and seperating code into different scripts for no reason. :smiley:

Yeah you’re right, but how long should a script be? Should i opt for having multiple scripts for better readability or do as much as possible in 1 script?

Depends on the complexity of your game.

ModuleScripts are basically also scripts that other scripts can access, whether that would be through reusable utility functions or frameworks, providing organization. You will still need a Script or a LocalScript to run them.

If it’s something simple like an obby and you would rather just run code straight up, there is no need to use them.

Modules are used when:

  • You need to store something, sort of communication between scripts
  • You want to shorten a part of your code ( RockModules, TweeningModules, ETC. that will save you some time)
  • Rewriting roblox core mechanics, some crazy people indeed do that
  • wtv you can think of

You cant do everything inside a module, you still need LocalScripts for your ServerSided scripts to work, And ServerSided scripts to make your Modules work

You should have generally as many scripts as you need, but only as many as you need. This is where modules come in. Honestly, i was always confused by modules too, but i understand now and i’ll try to explain it to you.

Modules are use so you don’t have to repeat yourself. You don’t need a new script in each KillPart for an obby. Instead, you would use a module and the CollectionService. The CollectionService is basically where you can add a tag to certain parts, use a module to check if a part :HasTag and then run a function.

Modules can also be used for datastores and other systems where you don’t want to use a bunch of scripts. Modules store information like tables that can be accessed in other scripts. They are typically meant to optimize your game.

Just remember you need to require any modules using a server script before being able to run them.

Module docs

CollectionService

Well, why wouldn’t I use a normal script instead? And also another question, should I generally opt for using multiple scripts or have 1 script do as much as possible?