Class:ModuleScript

A script fragment. Only runs when another script uses require on it. This class was added in version 0.131.

How They Work
ModuleScripts are ran using require(module). Modules must return something, which is the return value of the require function. All code is ran in the module when called and the return type is returned. This is usually a table of properties, functions, and events, or a function which does something to the game. However, the return type can be anything, including.

Private Modules
If a ModuleScript is renamed to "MainModule" and uploaded as a Roblox model, it can be called by using require([model id]). This is commonly used to create free models which contain code that is private, or is not wanted being shared by the owner. On December 5, 2018, announced the removal of this feature to be on February 1, 2019. The removal was delayed until February 25, when the feature was finally removed.

The following example uses private modules.

Code in MainModule: MainModule is published to Roblox and given the id of '187'

Code in Script: Notice how the code inside the module script cannot be retrieved, because a table is returned instead of the script being returned.