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 nil.

Private Modules

As of February 25, 2019, private modules must be free to take or owned by the creator in order to be used in games.

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, Seranok 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.

  • Tree-collapse
    ExplorerImageIndex 19
    • ExplorerImageIndex 76
    • ExplorerImageIndex 6

Code in MainModule:

local module={}
module.Code = 10
return module

MainModule is published to ROBLOX and given the id of '187'

Code in Script:

local module = require(187)
print(module.Code) --> Prints 10

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


Pubfield Content LinkedSource

Sets the module's Source to an online Lua file or a different script in-game.

Category: Data.

Serialization: can save and load.

Protfield ProtectedString Source

Determines the source code which will run when the module is required.

Category: Data.

Read security: PluginSecurity.

Write security: PluginSecurity.

Serialization: can save and load.

External links

Community content is available under CC-BY-SA unless otherwise noted.