Skip to main content

ModuleScript

Inherits from BaseScript

BETA Feature

ModuleScripts are currently in BETA and its behaviour may change at any point, so use it at your own risk.

Current Issues:

  • You can't edit data such as tables that are imported from a ModuleScript

ModuleScripts are specialized scripts to hold data that can be accessed by other scripts using the require() function.

It is important to define and return a table in a ModuleScript. When the place starts, the server and the client will run the ModuleScript once and store the result for other scripts to retrieve with require().

Polytoria's script run order prioritizes ModuleScripts.

When trying to require a specific module script, put the path to the ModuleScript in the require function.

Example

ModuleScript named Structures located in game["ScriptService"]

local Structures = {
["Tower"] = {
["Description"] = "This tower will obliterate any enemies on the way to the castle!",
["Price"] = 95,
["AttackDamage"] = 5
}
}

-- Make sure to return the table to be able to access it in other scripts!
return Structures

In a Script/LocalScript:

wait(0.1) -- The ModuleScript might only start running after this Script/LocalScript began running and thus this wait() is necessary
local Structures = require(game["ScriptService"]["Structures"])

print(Structures["Tower"]["Description"]) -- Prints out "This tower will obliterate any enemies on the way to the castle!" like how it was defined in the ModuleScript above.

Summary