When should I use specific scripts?

What situations should I use the 3 types of scripts? ( Server Script, Local Script, and Module Script ).

Im learning about module scripts, but Im confused on when I should use them or pair them with other scripts.

1 Like

Module scripts could be useful for everything.

Here are some exampls :

-Game recipes.
-Pets rarity [and chances].
-Product shop[ dev product, gamepasases, etc].

Now, in addition to all of these, module functions can help you save time and instead of doing the same script for each thing [ for e.g: intead of making a script that gives cash, inside of each npc, you could just manage that in the module script].
Meaning - module scripts not only do they save time, but also help you manage your game better and cleaner.

Now -
It’s always important to store them in either ServerScriptService [ could be under a script], or serverstorage [ can be accessed only from the server].
The reason : module scripts could be viewed by exploiters if they were on a client side [ or replicatedstorage].

It’s important to understand :
Module scripts dont run by themselves. They have to be required ; could be either from the client or the server.

How to require a module script:
In this example, I assume you’ve put the ModuleScript under a script inside ServerScriptService

local myModule = require(script.Module)

Server scripts are run by Roblox’s server that is running the game and handling its players. You use these for things that should happen to all players, such as moving players.

Local scripts are run by the player’s computers, and are used for things that only happen locally like UI.

Module scripts aren’t like local scripts or server scripts, and are used to store data, such as functions and variables that can be accessed by any script that calls the require function on them.


Server scripts: Used for handling actions that handling actions that have to be replicated across all clients and for using some services like Datastore.

Local scripts: Used for changing local objects, like the camera. Can also be used for player inputs (like in GUI), keys pressed, and mouse clicks.

Module scripts: Basically, a storage container for functions and tables. They do not do anything by themselves, but other scripts can use the items that they store. For example, I can put a table of item configurations inside of a module script and have other scripts look at that table.


How would you access the player’s UI / All player’s UI if you wanted to make a UI change for all players? ( e.x. Making a edit on a UI’s text )

The actual editing of the UI would be done by a local script, but if you wanted to make the change through the server you would use a RemoteEvent.

For more information about remotes, you can read this article.