What is a module script and what does it do?

Hello there! I have just discovered a new script called module script, and i was curious on what it does.
Ik that regular scripts are used objects, instances and services and more.
Ik that local scripts are used for clients.
However idk what module scripts are used for.
And of course i searched on the developer hub, but im still not getting it.

2 Likes

Here’s an old response I wrote on a similar topic.

3 Likes

Modulescripts are scripts that can be ran and used by other scripts and localscripts through the require function, when required they can return a value, similarly to functions, except it can only return a single value.

Example:

--Modulescript

local foo = "bar"

return foo
--Script

print(require(workspace.ModuleScript))
-- bar
1 Like

If you want to return many values use tables
–Module script

local table = {true,13,"Hi",game.Workspace}

return table 

–Normal script

local theTable = require(TheModuleScript)
local hi = theTable[3]
local theNumber = theTable[2]
print(hi,theNumber) -- hi13