Draft preview · this lesson is still being technically validated. Browser experiments and reference material remain available; trusted completion is enabled after publication.
Share a behavior through a ModuleScript
v2 · Activity 1 of 0 · modules · require · 28 min Requires Roblox Studio
Chapter outline
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.
Your task
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 |
|---|
Syntax in this activity
New syntax: modules, require
Earlier ideas used here
- cooldowns
- cleanup
- prompt-validation
Self-check rubric
- Both objects use the same module implementation.
- Changing the module color changes both on the next Play.
- Requiring the module without invoking apply does not style a new prop.
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.
Build this hierarchy
Workspace/LampA (Part) Workspace/LampB (Part) ServerScriptService/LampStyle (ModuleScript) ServerScriptService/ApplyStyles (Script, RunContext=Server)
- Create two Parts with the exact names and positions -4,3,0 and 4,3,0.
- Create the module and controller with the correct script classes.
ServerScriptService/LampStyle.luau
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 LampStyleServerScriptService/ApplyStyles.server.luau
Server 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"))Expected output
- Both lamps become anchored orange Parts.
- Server Output names LampA and LampB.
Studio assessment checklist
Multiplayer tests
- Run a local server and at least one client; compare server and client context where the activity uses both.
Troubleshooting and production considerations
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.
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.
Reset starter
Replace this code with the starter? Download your draft to keep a copy.
Code
Studio source fileEdit 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.