Questions about ModuleScripts

Why use them over normal scripts?
What do they do that normal scripts can’t do?
How do you use them?

I’d recommend you having a look at:

ModuleScript | Roblox Creator Documentation

1 Like

I understand it a little better now. If I interpreted it correctly, you can create a function in a module script and then call upon from anywhere whenever you need to use that function?

I use module scrips all the time! For example I have a module script that tells me which season my game is in. Script below.

local Season = {
	SeasonData = {
		NewYears = false,
		Valentines = false,
		Summer = true,
		July4th = false,
		Halloween = false,
		Winter = false,
		Christmas = false,
	}
}

return Season

They hold data that can be accessed by any script.

Look that one up. :slight_smile:

2 Likes

Modules are really good for storing values and sharing them across scripts, lets we have 2 types of scripts;

LocalScript
Script

LocalScript

This is the sort of script to run for client, anything related to whatever you see on your screen is the client side of the game, you can change things on client but it won’t replicate to server and is most of the time anything done on client like UI and tweening is smooth because it doesn’t require to catch up with the server changes which has slower latency. These scripts cannot interact with any server created objects and any changes are only applied to you.

Scripts

Normal scripts are about doing server stuff; calculations, signaling, services etc… Server is where any changes are applied to everyone on the server but they cannot interact with specific client objects like UI. As stated previously they have latency compared to client and cannot interact with locally created objects and can interact with other server scripts through BindableEvents

Modules

Now modules give us a lot of cool stuff we can do, modules can be used as storage units for scripts. You cannot store tables, values or anything in usual scripts or localscripts because there is no way to pass them on unless you bind a BindableEvent to it. All scripts run upon compiling, Modules only ran when required making them unique.

What is requiring you may ask? Requiring is when you use require(module script location) this instantly returns the module back to who requested it, placing a module in ReplicatedStorage will allow you to return the module’s content to Client/Server with no server latency to the receiving user.

Modules can also be used with OOP. An industry standard allowing scripts to interact with each other, to put in simple words I can make a function inside of a module and then require that module from any other script in-game and use the coded in function without having to use any remotes or events to do so making them really unique. However if a module is placed in a server only location like ServerScriptService only other server scripts can access them, this goes for client respectively as well.

More on OOP:

1 Like

Not sure which one to put as the solution, all are great explanations and I get it now.