Draft preview · this lesson is still being technically validated. Browser experiments and reference material remain available; trusted completion is enabled after publication.
v2 · Activity 1 of 4 · modules · require · 28 min Requires Roblox Studio
A ModuleScript returns a value, commonly a table of functions. require loads that value in the caller’s environment. Loading a module does not automatically call every exported function.
Keep the module in ServerScriptService when only the server needs it. A module placed in ReplicatedStorage can be read by clients, so it must not contain secrets.
Create LampStyle with apply(part). Set an anchored lamp orange and print its name. Use the same module from one server controller for LampA and LampB.
Interface: Complete the documented Studio hierarchy and self-check the behavior outside the browser.
| Input | Expected |
|---|
local Labels = {}
function Labels.describe(name) return "Workshop: " .. name end
return LabelsThe returned table is the interface. A caller explicitly invokes Labels.describe.
New syntax: modules, require
Your explanation is a self-check. Exact wording is not automatically graded.
Self-checked Studio exercise. A saved checklist records your own review; no uploaded place file or screenshot is executed here.
Workspace/LampA (Part) Workspace/LampB (Part) ServerScriptService/LampStyle (ModuleScript) ServerScriptService/ApplyStyles (Script, RunContext=Server)
ModuleScript exports apply.
local LampStyle = {}
function LampStyle.apply(part)
assert(part:IsA("BasePart"), "LampStyle requires a BasePart")
part.Anchored = true
part.Color = Color3.fromRGB(234,120,40)
print("Styled", part.Name)
end
return LampStyleServer controller calls the interface for two props.
local LampStyle = require(script.Parent.LampStyle)
local Workspace = game:GetService("Workspace")
LampStyle.apply(Workspace:WaitForChild("LampA"))
LampStyle.apply(Workspace:WaitForChild("LampB"))require expects a ModuleScript Instance, not an ordinary Script.
Circular module dependencies can stall loading; keep this interface independent.
This is a bounded learning lab. It has not been executed in an approved Roblox Studio environment by this website.
A checked checklist records your own review, not automated project competence or a community verification.
A ModuleScript returns a value, commonly a table of functions. require loads that value in the caller’s environment. Loading a module does not automatically call every exported function.
Keep the module in ServerScriptService when only the server needs it. A module placed in ReplicatedStorage can be read by clients, so it must not contain secrets.
Within one Luau environment, repeated require calls reuse the returned module value. That makes shared module state a deliberate design choice; this module keeps its work in the supplied object instead.
Replace this code with the starter? Download your draft to keep a copy.
Edit and run these files in Roblox Studio. This browser has no Roblox services, physics, or replication.
Your output will appear here.
Sign in with RoCreators to save private progress across devices. Community verification is separate.