World building in code: MapBuilder, lighting, atmosphere

Build a Roblox map in Luau instead of by hand. Read Beacon Yard's MapBuilder and WorldLook, change the walls, the lighting and the atmosphere, and learn when studios build in code.

Project lesson, about 70 minutes, 11 steps

By the end you can

  • Read MapBuilder.build and name the parts it creates under Workspace.Yard, with their stud sizes
  • Separate the dusk that WorldLook sets at boot from the two Lighting values a drill changes
  • Explain why a part you place in Workspace.Yard by hand disappears on Play, and where to add it instead

Before this: Parts, models, materials and pivots, The data model: every service and where things live

Step 1 of 11

Press Play and the yard appears

At m05-the-round, where this lesson starts, Explorer still shows a hand-placed Yard folder in edit mode. By m06-drone-wrench, where the BuildAlong takes you, that folder is gone before you press Play. Press Play and it appears: a 96 by 96 stud slab, walls, two gates, six glowing pads, a beacon and a shop. A script built all of it in the first fraction of a second.

An orbit of the yard during Play. Nothing in this clip was placed by hand.

Transcript
  1. 0:00 Play builds Workspace.Yard from MapBuilder.
  2. 0:02 The base is 96 studs across. The walls are 10 studs tall.
  3. 0:05 Six pads sit on a circle of radius 22.
  4. 0:08 The north gap is 16 studs, closed by two gates until a drill starts.

That script is MapBuilder.build, in src/server/MapBuilder.luau. Up to m05 the yard lived in default.project.json, part by part. At m06 it moved into code, because a loop can place six pads on a circle and a helper can make four signs that match.

Choose one

From m06 on, where does Workspace.Yard come from?

From m06 on, where does Workspace.Yard come from?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 2 of 11

Folders in a cabinet

Everything in a Roblox game is an InstanceInstanceAny object in a Roblox game: a part, a script, a folder, a sound.Think of it as a folder or file in a filing cabinet., and every instance has a parent. Explorer draws that as a tree. MapBuilder.build first deletes any old Workspace.Yard, then makes a new Folder named Yard and parents each part to it.

The game is a filing cabinet. Services such as Workspace and Lighting are drawers, and folders and models hold the parts. A script finds a part the way you find a file: by its path, such as Workspace.Yard.CoinPads.Pad3.

Think of it as Folders in a filing cabinet

Both sidesRemember: The instance tree is folders in a filing cabinet.

function MapBuilder.build(): MapHandles
	local previous = Workspace:FindFirstChild("Yard")
	if previous then
		previous:Destroy()
	end
 
	local yard = Instance.new("Folder")
	yard.Name = "Yard"
	yard.Parent = Workspace
Predict the output

In edit mode you make your own Folder named Yard in Workspace, put a Part named Bench inside it, and press Play. What happens to Bench?

local previous = Workspace:FindFirstChild("Yard")
if previous then
	previous:Destroy()
end
In edit mode you make your own Folder named Yard in Workspace, put a Part named Bench inside it, and press Play. What happens to Bench?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 3 of 11

Walls from five numbers

Every wall size comes from a few locals at the top of the wall section. Distances are in StudStudRoblox's unit of length. Sizes, positions and speeds are all in studs.Think of it as one square on the grid of the baseplate.s, Roblox's length unit1. The inner yard is 88 studs, walls are 2 thick and 10 tall, and each gate is 8 wide.

	local wallHeight = 10
	local wallThick = 2
	local inner = 88
	local halfInner = inner / 2
	local wallCenter = halfInner + wallThick / 2
	local outerSpan = inner + wallThick * 2
	local gateWidth = 8
	local gap = gateWidth * 2
	local segment = (outerSpan - gap) / 2
	local segmentCenter = gap / 2 + segment / 2
	local wallY = wallHeight / 2

Each wall is an anchored part. Anchored parts stay where you put them and ignore gravity2. The server can still move one by writing its CFrame, which is how the gates slide open in the round lesson. A CFrame holds a position and a rotation together3.

Work it out

inner is 88 and wallThick is 2. MapBuilder computes wallCenter = halfInner + wallThick / 2. How far from the middle of the yard is the centre of each wall, in studs?

studs

Link to this step · This confused me

Step 4 of 11

Six pads on a circle

The pads are where code beats hand placement. One loop puts six pads on a circle of radius 22 around the beacon. Each pad gets a name, a PadIndex attribute and the tag CoinPad, which the coins lesson uses.

	for index = 1, 6 do
		local angle = (index - 1) * (math.pi * 2 / 6)
		local pad = anchoredPart(
			"Pad" .. tostring(index),
			Vector3.new(4, 1, 4),
			CFrame.new(math.cos(angle) * 22, 0, math.sin(angle) * 22),
			PAD_COLOR,
			Enum.Material.Neon,
			padsFolder
		)
		pad:SetAttribute("PadIndex", index)
		CollectionService:AddTag(pad, "CoinPad")
		table.insert(pads, pad)

The loop starts at 1, but the angle uses index - 1, so pad 1 sits at angle 0, due east. Run the same maths and read the positions.

Luau
Ctrl Enter runs the cell. Checked against the expected output
Choose one

You change both 6s in the loop to 8. What do you get?

You change both 6s in the loop to 8. What do you get?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 5 of 11

Landmarks and sightlines from spawn to beacon

Building a map in code is not only geometry; it also decides where a new player walks in the first second. Two level-design ideas explain why MapBuilder.build puts every piece where it does:

  • Landmarks are tall, bright, unmistakable objects you can orient by from anywhere in the yard. The glowing cyan Beacon at (0, 0) rises to y = 6 with a 24-stud PointLight and 10 particles per second. Secondary landmarks anchor the edges: the orange Quartermaster shop at (22, 22) and the twin hazard-striped Yard Gate at (0, 45).
  • Sightlines are the clear lines of view between where a player stands and where you want them to go. MapBuilder places Spawn at (-30, 3, 0), puts Pad4 straight east at (-22, 0) (8 studs ahead), and leaves the corridor to the Beacon at (0, 0) completely open.
Sightline from spawn to the beaconThree boxes left to right along the east axis: Spawn at (-30, 0) leads 8 studs to Pad4 at (-22, 0), which leads 22 studs to the glowing Beacon at (0, 0), with labels marking the Shop and Yard Gate to the sides.8 studs22 studsSpawn(-30, 3, 0)Pad4 (+5)(-22, 0), 8 studsBeacon(0, 0), y=6 glowShop (22, 22)Yard Gate (0, 45) + hazard stripe
An unobstructed west-to-east line pulls a new player over a coin pad and straight to the beacon.

Without a single tutorial popup, the sightline teaches the first two steps of the core loop. When you expand the yard into multiple zones with greyboxing, flow and choke points in Module 14, see Prototype fast: paper, greybox, blockout.

Choose one

You add a 10-stud-tall decorative crate stack at (-15, 5, 0) right between Spawn (-30, 3, 0) and the Beacon (0, 0). What does that break?

You add a 10-stud-tall decorative crate stack at (-15, 5, 0) right between Spawn (-30, 3, 0) and the Beacon (0, 0). What does that break?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 6 of 11

Dusk is set by a script too

The sky, the haze and the warm light come from WorldLook.start, which runs before the map is built. Lighting is a service, and its properties set the look of the whole place for every player4. Haze lives on an Atmosphere object under Lighting5.

	Lighting.ClockTime = 17.4
	Lighting.Brightness = 2.6
	Lighting.ExposureCompensation = 0.45
	Lighting.GeographicLatitude = 18
	Lighting.Ambient = Color3.fromRGB(92, 84, 104)
	Lighting.OutdoorAmbient = Color3.fromRGB(176, 132, 104)
	Lighting.EnvironmentDiffuseScale = 0.55
	Lighting.EnvironmentSpecularScale = 0.55
	Lighting.ShadowSoftness = 0.35
	Lighting.GlobalShadows = true
 
	local atmosphere = effect("Atmosphere", "BeaconAtmosphere") :: Atmosphere
	atmosphere.Density = 0.18
	atmosphere.Offset = 0.18
	atmosphere.Color = Color3.fromRGB(210, 168, 132)
	atmosphere.Decay = Color3.fromRGB(92, 64, 88)
	atmosphere.Glare = 0.22
	atmosphere.Haze = 0.75

A drill changes the look again, but only two values. RoundService saves ClockTime and Ambient when it starts, moves the clock to 18.4 and a red ambient while the drill runs, then puts both back.

Starting a drill: the gates open and the clock jumps from 17.4 to 18.4.

Transcript
  1. 0:00 The beacon prompt starts the drill for the whole server.
  2. 0:05 The gates tween open over one second.
  3. 0:08 ClockTime jumps to 18.4. Exposure stays where WorldLook set it.
Choose all that apply

Which Lighting values does a drill change? Pick every one.

Which Lighting values does a drill change? Pick every one.

Press 1 to 5 to choose, Enter to check.

Link to this step · This confused me

Step 7 of 11

Materials that survive a missing upload

WorldLook.apply gives a part its base material and, when it exists, a textured MaterialVariant. The walls become steel and the base becomes asphalt. A running server cannot set MaterialVariant.BaseMaterial, so the variants are written into the place file by scripts/gen-assets.mjs from your own texture ids. If a variant is missing, the part keeps the plain material and boot prints one [Ids] warning.

Roblox Studio
Roblox Studio during Play, looking down on Beacon Yard: the ring of yellow pads, the cyan beacon in the middle, the north wall and the HUD.

Select a numbered pin, or a row below, to read what it marks.

The yard from above during Play. Select a pin to see which function made it.

function WorldLook.apply(part: BasePart, slot: Slot)
	local style = SLOTS[slot]
	part.Material = style.material
	local variant = MaterialService:FindFirstChild(style.variant)
	if variant ~= nil and variant:IsA("MaterialVariant") then
		part.MaterialVariant = style.variant
Choose one

You run Beacon Yard with every texture id still 0. What do the walls look like?

You run Beacon Yard with every texture id still 0. What do the walls look like?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 8 of 11

Where the cabinet picture breaks

In a real cabinet, a file is the same file in any drawer. In Roblox, the drawer changes what the thing does. Try to answer before you open the breakdown.

Where does it break?“Folders in a filing cabinet” is a good picture of the instance tree. Where does it stop being true?

It breaks here. Location changes behaviour: the same part renders in Workspace, is invisible and server-only in ServerStorage, and a script runs or not depending on its container.

The true model. Every instance has one parent, and the container decides what it does: whether it renders, replicates, runs or is simulated. Moving an instance between services changes its behaviour, not just its address.

Match the pairs

MapBuilder builds a part. Match where it is parented to what happens.

Link to this step · This confused me

Step 9 of 11

Build it: from a hand-placed yard to MapBuilder

Other ways pros do this

OptionWhat it isWhen pros pick itTrade-offs
Build in code (MapBuilder)A server script creates every part at boot.Repeated or measured layouts, procedural maps, and repos that need readable diffs.You cannot drag a wall in edit mode, and an artist has to read Luau to change the map.
Build by hand in StudioParts and models placed with the Move and Scale tools and saved in the place file.Most hand-crafted maps. Builders and level designers work this way in nearly every studio.Binary place files do not diff, so two builders editing the same map need Team Create or Packages.
PackagesReusable models that update everywhere they are used.Shared props and kits across places or teams.Versioning lives on Roblox, not in Git.
TerrainVoxel ground, water and rock painted with the Terrain Editor or generated by script.Natural landscapes.Heavier to stream and harder to keep exact measurements.
  • src/server/MapBuilder.luau
  • src/server/WorldLook.luau
  • src/server/init.server.luau
  • default.project.json
  1. In the game repo, run git diff --stat m05-the-round m06-drone-wrench -- src default.project.json.

    You should see git lists MapBuilder.luau and WorldLook.luau as new files and default.project.json with many lines removed.

  2. Check out m06-drone-wrench, open default.project.json and src/server/init.server.luau, and find the two calls.

    You should see The hand-placed Yard entries are gone from default.project.json, and init.server.luau calls MapBuilder.build after WorldLook.start.

  3. Run rojo serve, connect from Studio, and press Play.

    You should see Explorer shows no Yard in edit mode. After Play, Workspace.Yard holds Base, the walls, GateLeft, GateRight, Spawn, Beacon, CoinPads and Shop.

  4. In MapBuilder.luau, change wallHeight from 10 to 18, save, and press Play again.

    You should see The walls and both gates are 18 studs tall. The pads and beacon do not change.

  5. Put wallHeight back to 10. Later lessons assume it.

    You should see The walls are back to 10 studs.

Link to this step · This confused me

Step 10 of 11

Challenges

Level 1, Apprentice

Challenge

Prove that wall height is a map number, not a Config number. Make the walls 18 studs tall, run the suite, then put them back.

Start from
The game at milestone m06 (download)

Done means

  • The walls and gates are taller during Play
  • The test suite's config_numbers check still passes
  • wallHeight is 10 again afterwards

Meet the criteria above, then record your own result. No test grades this check.

Level 2, Builder

Challenge

Add a part that survives Play by creating it in MapBuilder.build.

Start from
The game at milestone m06 (download)

Done means

  • A small anchored part exists in Workspace.Yard during Play
  • Stopping and pressing Play again does not make two copies
  • The extra code is removed before the next lesson

Meet the criteria above, then record your own result. No test grades this check.

Choose one

Why does the canopy challenge ask for CanCollide off?

Why does the canopy challenge ask for CanCollide off?

Press 1 to 4 to choose, Enter to check.

Level 3, Professional

Challenge

Put a roof over the beacon that does not block anyone. The check is challenges/world-building.luau in the game repo.

Start from
The game at milestone m06 (download)
Grade it
To grade work from an earlier milestone, apply your challenge changes to a checkout based on m14-ship, which includes the Course Runner. In Studio, press Play, then run game.ServerScriptService.RunGameTests:Invoke("world-building", "world-building-canopy") in the server command bar. Copy the pass code from Output.

Done means

  • Workspace.Yard.Canopy exists, size 20 by 1 by 20
  • Its X and Z are within 1 stud of 0, and Y is at least 12
  • It is anchored with CanCollide off
  • The test prints TEST PASS for canopy_present, canopy_size, canopy_place and canopy_flags

The Course Runner prints this code when the test passes.

Link to this step · This confused me

Step 11 of 11

Recap

Retiring the analogy

You no longer need “folders in a filing cabinet”. Every instance has one parent, and the container decides what it does: whether it renders, replicates, runs or is simulated. Moving an instance between services changes its behaviour, not just its address.

Recap

  1. MapBuilder.build destroys the old Workspace.Yard and builds a new one at boot, so hand-placed parts there vanish on Play.
  2. Sizes come from locals in the builder (88-stud yard, 2-stud walls 10 tall, pads on a 22-stud circle); Config holds timers and prices, not layout.
  3. WorldLook sets the dusk and materials once; a drill only changes ClockTime and Ambient, then restores them.

The instance tree is folders in a filing cabinet, until location changes behaviour: the same part renders in Workspace, is invisible and server-only in ServerStorage, and a script runs or not depending on its container.

Next Coins: touch, debounce, respawn, leaderstats

Link to this step · This confused me

Sources
  1. Roblox units. Roblox Creator Documentation, checked 2026-11-13.
  2. Parts. Roblox Creator Documentation, checked 2026-11-13.
  3. CFrames. Roblox Creator Documentation, checked 2026-11-13.
  4. Global lighting. Roblox Creator Documentation, checked 2026-11-13.
  5. Atmospheric effects. Roblox Creator Documentation, checked 2026-11-13.