Uses Of Modules

What are the uses of module scripts? I cant figure out why I should use a module script over a regular script. Like when should I use a module script over a regular script. Idk if this is the right place to post this, but eh.

They’re mainly used for when you need to repetitively use the same functions over multiple scripts, such as having a kick function in a module script and referencing it in many of your normal server-scripts. You don’t HAVE to use them, but they can be efficient, especially for sending data to more than one script.

Module scripts serve as an excellent tool to clean up your code if you use dozens of functions in one script alone. There are many situations when you would want to use module scripts, but the general idea is that it allows you to clean up your code and write functions without repeating them.

1 Like

As a reference, if I was to make a simulator what could I use a module script for?

Rarities for the pets When they hatch

You can have one in the server to handle any money changes. If a player buys something, you can call the module with the player and type of item they want to buy and it would change their money accordingly.

Module scripts are good for data(And using functions that take forever so you dont always have to retype). Pretend your not using values but using a table how will you access that? Use a module to edit stuff. I also use it for stuff that take me forever for example lightning is in my module because Its just fast

You could use a module script to store data. For example, in a simulator you would have a bunch of different types of pets and you can store their data such as, rarity, price, function, etc. If your game had a lot of reused functions such as spawning enemies or enemy attacks, You could put all the functions of the enemies inside the function and have all the enemies use the functions from that module. Technically, everything could be made without Modules but they make your life way easier and you can organize and make your code way cleaner.

Alright I now have a better understanding of the uses of module scripts. Thanks!