Skip to content

ModuleScript

Shared code that Scripts and LocalScripts import. It never runs on its own.

  • Inherits: Instance
  • Creatable: No. ModuleScripts are added in Rally Studio.
  • Replication: The object is never sent to players, but its code is, inside every LocalScript that imports it.

Import a ModuleScript by its path in the tree, or relative to the importing script’s parent:

// In ReplicatedStorage/Config (a ModuleScript):
export const ROUND_SECONDS = 90;
export const TEAM_COLORS = ['#ff3b30', '#2c7afd'];
import { print } from '@rally/sdk';
import { ROUND_SECONDS } from '@game/ReplicatedStorage/Config'; // by path
import { openDoor } from './DoorLogic'; // a ModuleScript next to this script
print(ROUND_SECONDS);
openDoor();

A module’s code is compiled into every script that imports it. Because of that:

  • A ModuleScript imported by a LocalScript reaches players’ devices as part of that LocalScript, wherever the module is stored.
  • ModuleScript objects aren’t part of a running game: published games and tests contain only Scripts and LocalScripts.
  • Imports can only name ModuleScripts, and two objects at the same path can’t be imported.

Type: string · Default: '' · Access: read-only · Replicates: no

The module’s code. Game code can’t change it.

Inherited from Instance: name, archivable, id, className, parent, destroyed

Inherited from Instance: getPropertyChangedSignal, setAttribute, getAttribute, getAttributes, getAttributeChangedSignal, getChildren, getDescendants, findFirstChild, findFirstChildOfClass, findFirstChildWhichIsA, findFirstAncestor, findFirstAncestorWhichIsA, waitForChild, isA, isDescendantOf, isAncestorOf, getFullName, clearAllChildren, destroy, clone, toString

Inherited from Instance: changed, childAdded, childRemoved, descendantAdded, descendantRemoving, ancestryChanged, destroying, attributeChanged