Roblox Wiki
Advertisement
Roblox Wiki

ModuleScript is a Script light iconScript dark iconScript fragment. It only runs when a Script light iconScript dark iconScript uses require() on it. The class was added in version 0.131.

Function[]

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[]

⚠️
Warning
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.

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.

Properties

LinkedSource: ContentId

  • DeprecatedThis member will be phased out and should be avoided while it is still available.
This API member has existing documentation in this page's Member list template.
This class member is missing documentation. Create or add to its subpage at Class:ModuleScript/LinkedSource.
  • Category: Data.
  • Serialization: can save and load.
  • Thread safety: read safe

Source: ProtectedString

This API member has existing documentation in this page's Member list template.
This class member is missing documentation. Create or add to its subpage at Class:ModuleScript/Source.
  • Category: Data.
  • Serialization: can save and load.
  • Thread safety: read safe

Removed members

Properties

  • CoreScriptModified

External links[]

Advertisement