ModuleScript

Inherits LuaSourceContainer

ModuleScript contains Lua code that returns a value which can be required by other scripts.

Examples

-- In ModuleScript
local module = {}
function module.greet(name)
return "Hello, " .. name
end
return module

-- In another Script
local myModule = require(script.Parent.ModuleScript)
print(myModule.greet("World"))

Properties

ModuleRef

int

Reference to the cached module value in the Lua registry

Loaded

bool

Whether the module has been loaded and cached

Enabled

bool Inherited from LuaSourceContainer

When true, the script can execute; when appropriate.

Source

string Inherited from LuaSourceContainer

The Lua source code to execute.

SourcePath

string Inherited from LuaSourceContainer

File path to fetch and load source code from.

Methods

Require()

int

Loads and returns the module value

local module = require(game.ServerScriptService.MyModule)