Modules✎
What a script requires and the services it fetches, where you declare them, and what each runtime resolves.
Pending review
A module is code in another file that this one uses. Roswaal writes the require for you — but only ever for a module you have declared, and each declaration writes exactly one, at the top of the generated file.
Tip
Declaring one
Modules live in the Variables panel, under Services and modules, each under the service it is required through. It is the same question the variables answer — what does this script have to hand — and a dependency belongs somewhere you can see it rather than somewhere you go looking.
| Field | What it is |
|---|---|
| Name | The local it binds to, and what the pill shows. Yours to choose — see below |
| Module | What goes inside require(...): a string, or on Roblox where the ModuleScript sits |
| Members | Names pulled off it into locals of their own, comma separated |
Drag a module onto the canvas for a Get Module pill — one output, no header, exactly as a variable gives you a Get. Four of them still write one require, because the declaration is on the script rather than on any of the pills.
Require at Top declares one on the canvas instead, for when you would rather see it there. It takes the same specifier and hands back the same module.
Or drag a ModuleScript from the DataModel browser onto the Modules heading, or its graph from Graphs or its file from Output: it is declared under its own name, by where the project's node map puts it. Dropping one that is already declared changes nothing.
A Require Module or Require at Top already on the canvas can be moved here: right-click it and choose Promote to Modules. It becomes a Get Module pill for the declaration, keeping its wires, and any module function called through it is called through the declaration.
What goes in the box
A string must start with a prefix. That is not a house style: an unprefixed path is an error in Luau itself, since the require rules were amended — require("Foo") used to resolve and now does not. On Roblox you can name where the module sits instead, with no quotes: see below.
| Form | Roblox | Lune | What it reaches |
|---|---|---|---|
./name | Yes | Yes | A sibling of this file |
../name | Yes | Yes | Up one, then down |
@self/name | Yes | — | A child of this script |
@game/Service/name | Yes | — | Down from the DataModel root |
@lune/fs | — | Yes | Lune's standard library |
@alias/name | Not yet | Yes | An alias from a .luaurc |
ReplicatedStorage.Shared.Greeter | Yes | — | The ModuleScript at that place |
script.Parent.Util | Yes | — | Up from this script, then down |
Warning
@lune/fs in a Roblox graph is an error. A .luaurc alias is a warning in Roblox, which does not resolve them yet — see Aliases and .luaurc.By where it sits
Most Roblox code requires a module by the instance, not by a string, and the Modules list takes that too. Start from a service, script or workspace, and write the path the way you would in Luau:
| Written | Required as |
|---|---|
ReplicatedStorage.Shared.Greeter | require(ReplicatedStorage.Shared.Greeter) |
game.ReplicatedStorage.Shared.Greeter | The same |
game:GetService("ReplicatedStorage").Shared.Greeter | The same |
ReplicatedStorage:WaitForChild("Shared").Greeter | As written |
workspace["Main Menu"].Util | As written |
The service is fetched once, at the top, and the require reads it — the same local a Get Service for it reads. With no name given, the module is named after the ModuleScript.
Info
:WaitForChild(...). Anything else — another call, an operator — is an error rather than written, because a field in a panel is not somewhere code should be able to hide.Naming it yourself
The name is a choice, not a derivation. Two modules can genuinely want to be called util — ./combat/util and ./inventory/util — and only you can say which becomes combatUtil.
So a name you type is used exactly. It is never quietly turned into util2: two declarations wanting one name is an error naming both, because a file can bind it once and the fix is a rename that is yours to pick.
Members, and the Roblox datatypes in Lune
Members bind names from inside the module to locals of their own. It is Lune's own idiom, and it is what makes the Roblox datatypes work there.
local roblox = require("@lune/roblox") local Vector3 = roblox.Vector3 local CFrame = roblox.CFrame
With Vector3 bound, Vector3.new(1, 2, 3) means what it means in Roblox — so a graph moved between runtimes needs the declaration, not different nodes. Shadowing a name Luau provides is allowed here because it is the point; Roswaal warns, so that naming a module table is a decision rather than an accident.
Where the requires end up
At the top, in three bands with a blank line between: requires that need nothing above them, then the services, then requires through a service, under it in the services' order. The path decides the band: @game/ReplicatedStorage/Combat reads no service, so it does not wait for one. Declared services come first, then any a node asked for.
local Combat = require("@game/ReplicatedStorage/Combat") local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Greeter = require(ReplicatedStorage.Shared.Greeter)
Info
Drag a module in the Variables panel to change where it is required. It stays in its band, and under its service: a drop outside it is refused with the reason, and changing its path is what moves it. A require runs its module, so a move asks first and shows the Luau that changes.
Modules that require each other
Two modules that require each other as they load cannot both load: Roblox stops one with "Requested module was required recursively". Script analysis lists each ring under Project as a cycle, hand-written modules included.
Tip
Not reviewed yet