Procedural generation: noise, seeds, chunking

Generate a seeded scrap field around Beacon Yard with hashes, Perlin and value noise and chunks, run the noise in the browser, and move the heavy maths to Parallel Luau.

Lab lesson, about 70 minutes, 11 steps

By the end you can

  • Make random content repeatable with a seed and a stateless hash instead of math.random
  • Use noise (math.noise or hand-written value noise) to make placement cluster naturally
  • Split a large generated area into chunks and build only the chunks that are needed
  • Decide what generation work can run in Parallel Luau and what must stay serial

Before this: World building in code: MapBuilder, lighting, atmosphere, Parallel Luau: Actors and multithreading

Step 1 of 11

The empty field outside the walls

Press Play in Beacon Yard and walk to a wall. Inside, everything has a place: the base is 96 studs across, the walls enclose 88, the pads sit on a ring. Outside the walls there is nothing at all. MapBuilder builds the yard from numbers every time the server starts:

	-- Inner yard is 88 studs. Walls are 2 thick, so their centers sit at
	-- 45. North and south spans include the corners (92). The +Z wall
	-- leaves a 16-stud gap for two 8-stud gates.
	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

In this lesson you fill the field around those walls with piles of scrap. Nobody places them by hand. A few rules and one number, the seed, decide where every pile goes, and the same seed always gives the same field.

Work it out

From the code above: the walls' centres sit at wallCenter studs from the middle, and they are wallThick studs thick. How far from the centre does the outside face of a wall end?

studs

Link to this step · This confused me

Step 2 of 11

Rules instead of placement

Procedural generationProcedural generationContent placed by rules and numbers in code, instead of by hand.Think of it as a recipe for a level rather than the level itself. means writing the rules that place things, instead of placing them. You have already seen a tiny version: MapBuilder does not list six pad positions, it computes them on a circle.

	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)

A generator for a whole field needs three more ideas. A seed makes the randomness repeatable. Noise makes it look natural, with clusters and gaps instead of even sprinkling. Chunks split the field into squares so you only build the part you need.

Choose one

Using the loop above, where does Pad4 sit?

Using the loop above, where does Pad4 sit?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 3 of 11

Seeds: random, but repeatable

math.random gives a different field every time, and its answer depends on how many times it was called before. Generate chunk A then chunk B, and B differs from generating B first. For a world that must look the same to every server and every visit, use a seedSeedThe number that picks one world out of all the worlds a generator can make.Think of it as the page number in a book of random numbers. and a hash: a function with no hidden state that scrambles its inputs into a number between 0 and 1.

Run this. Same seed and cell, same number. Change the seed, and the whole field changes.

Luau
Ctrl Enter runs the cell. Checked against the expected output
Choose all that apply

Why does the scrap field use a seeded hash instead of math.random?

Why does the scrap field use a seeded hash instead of math.random?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 4 of 11

Noise: randomness with neighbours

Hashing every cell separately gives static, like an untuned TV. Real scrap piles up in heaps with clear ground between them. Noise is randomness where nearby points get similar values. Luau's standard library has math.noise(x, y, z), which returns 3D Perlin noisePerlin noiseSmooth random values where nearby points are similar; math.noise in Luau.Think of it as rolling hills instead of TV static. between -1 and 112.

Three things matter in practice:

  • Scale. Divide positions before sampling. math.noise(x / 32, z / 32) changes slowly over 32 studs; x / 4 is busy.
  • Seeding. math.noise has no seed parameter. Offset the input by the seed instead: math.noise(x / 32 + seed * 101.7, z / 32).
  • Whole numbers. Perlin noise is exactly 0 at every whole-number input, so never sample integer positions unscaled.
Predict the output

What does this print?

print(math.noise(3, 7, 0))
What does this print?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 5 of 11

Draw the field

math.noise is fine for most games. Writing your own noise once shows you what it does, and lets you seed it properly. Value noise puts a hashed random value at every whole-number corner and blends smoothly between the four corners around a point. The map below prints one character per 8-stud cell from -96 to 96 studs: Y is the yard and its margin, # is dense scrap, . is open ground.

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

Change SEED and run it again: a different field, with the yard in the same place. Change cellX / 4 to cellX / 2 and the heaps get smaller and busier.

Work it out

How many Y characters are there in each row that crosses the yard?

Link to this step · This confused me

Step 6 of 11

Chunks: build the field in squares

A field around a 96-stud yard is small, but the same code could fill thousands of studs. A chunkChunkA fixed square of a generated world that is built and removed as one unit.Think of it as one square of a tiled floor, laid only where people walk. is a fixed square of the world, here 64 by 64 studs, that the generator builds as one unit. Chunk coordinates come from floor division: x // 64. A server builds the chunks near players and skips the rest.

Think of it as Stage sets built as you walk

Both sidesRemember: Building the world near the player (chunks and StreamingEnabled) is stage sets built as you walk.

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

Because the hash has no state, any chunk can be built at any time, in any order, by any server, and it always comes out the same. That is what makes chunks safe to build lazily.

Work it out

Pad4 sits at x = -22. With 64-stud chunks, what is its chunk column, x // 64?

Link to this step · This confused me

Step 7 of 11

Where the stage-set picture breaks

Chunked generation and Roblox's streaming both build the world near the player, so they are easy to confuse. Answer before you open the breakdown.

Where does it break?“Stage sets built as you walk” is a good picture of building the world near the player (chunks and streamingenabled). Where does it stop being true?

It breaks here. There are two crews. Your generator decides what exists on the server; StreamingEnabled separately decides which of it each client has received, so a piece can exist on the server and still be missing on a client.

The true model. Chunked generation is your code creating instances on the server near players. StreamingEnabled is the engine sending only nearby instances to each client. Client code must handle parts that are not streamed in yet, whatever created them.

Choose one

The server generates the scrap chunks around every player. With StreamingEnabled on, a player far from a chunk looks for one of its piles in a LocalScript. What happens?

The server generates the scrap chunks around every player. With StreamingEnabled on, a player far from a chunk looks for one of its piles in a LocalScript. What happens?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 8 of 11

Build the field in Beacon Yard

The level 3 challenge's learner file, challenges/work/scrap_field.luau at m14-ship, is where the generator lives: generate(seed, chunkX, chunkZ) returns the piles for one chunk as plain tables. MapBuilder then turns them into parts. Keeping the maths free of instances means it can be tested without Studio and moved into Parallel Luau later.

Build along

m14-ship

  • challenges/work/scrap_field.luau
  • src/server/MapBuilder.luau
  1. Write generate with a seeded hash and value noise, as in the cells above. Keep every pile 52 studs or more from the centre on at least one axis.

    You should see The level 3 challenge prints TEST PASS for all five checks.

  2. In MapBuilder.build, after the walls, require the module, loop chunks -3 to 2 on both axes, and create one anchored, rusty Metal part per pile in a ScrapField folder under the yard.

    You should see Pressing Play builds Workspace.Yard.ScrapField with a few hundred anchored parts outside the walls and none inside.

  3. Use a fixed seed such as 7, play twice and compare a few piles' positions in the Explorer.

    You should see Stopping and pressing Play again rebuilds an identical field.

Roblox Studio
Beacon Yard seen from straight above in Studio with seed 7: heaps and open patches of rusty scrap piles on sand outside all four walls, and clear ground inside the keep-out square.

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

The yard from above with seed 7. The pins mark a dense heap, open ground, and the 6-stud margin outside the walls.

Choose one

Beacon Yard's MapBuilder destroys and rebuilds Workspace.Yard every time the server starts. What does that mean for the scrap field?

Beacon Yard's MapBuilder destroys and rebuilds Workspace.Yard every time the server starts. What does that mean for the scrap field?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 9 of 11

Heavy generation in Parallel Luau

Six chunks of scrap take milliseconds. Terrain voxels, caves or thousands of trees can stall a server for whole frames. Parallel Luau spreads work across CPU cores: put scripts under separate Actor instances, then call task.desynchronize() to run in parallel and task.synchronize() to return to serial3. Scripts in the same actor still run one after another, so you need several actors.

The rule that shapes the design: most reads are safe in parallel, but changing the shared world, such as parenting a part into Workspace, must happen in a serial phase. So compute the pile list in parallel (pure maths, like generate), then synchronize and create the parts. Roblox's own guide uses exactly this split for server-side procedural terrain, with workers receiving chunk messages through Actor:SendMessage3.

Other ways pros do this

OptionWhat it isWhen pros pick itTrade-offs
math.noiseBuilt-in Perlin noise in the Luau standard library.Most Roblox terrain and placement. Fast and always available.No seed parameter (offset the input instead), and exactly 0 at whole numbers.
Hand-written value or simplex noiseYour own noise on top of a seeded hash.You need true seeds, identical results outside Roblox (tests, tools), or a specific look.More code, and slower than the built-in unless you are careful.
Terrain voxels (WriteVoxels, FillBlock)Write noise-driven materials into Roblox Terrain.Hills, caves and water rather than separate props.Terrain has its own memory and streaming costs; props still need parts or models.
Hand-built in StudioPlace everything yourself, maybe with a scatter plugin.Small, curated spaces where each spot matters, like Beacon Yard's lobby.Every variation is manual work and lives in the place file.
Choose one

In a parallel scrap generator, which step belongs after task.synchronize()?

In a parallel scrap generator, which step belongs after task.synchronize()?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 10 of 11

Challenges

Level 1, Apprentice

Challenge

Tune the map: try seeds and the threshold until the field has a walkable path out of the gates.

Start from
The scrap-map cell on this page

Done means

  • You found a seed whose field leaves a clear path from the north gate (positive z) to the edge of the map
  • You changed the density threshold so roughly a third of the field is scrap
  • You can explain what dividing by 4 versus 8 does to the heaps

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

Level 2, Builder

Challenge

Build chunks lazily around players instead of all at boot.

Start from
m06-drone-wrench with the scrap field built

Done means

  • Only the chunks within 2 of any player exist on the server
  • Chunks that no player is near are destroyed after a few seconds
  • Walking away and back rebuilds an identical chunk

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

Work it out

The build-along loops chunks -3 to 2 on both axes at boot. How many chunks is that?

chunks

Level 3, Professional

Challenge

Start from the m14-ship tag in the game repo, then make the stock generator pass. It uses math.random and ignores the yard. Run it from the command bar with game.ServerScriptService.RunGameTests:Invoke("procedural-generation").

Start from
The game at milestone m14 (download)
Grade it
In Studio, press Play, then run game.ServerScriptService.RunGameTests:Invoke("procedural-generation") in the server command bar. Copy the pass code from Output.

Done means

  • challenges/work/scrap_field.luau gives the same piles for the same seed and chunk, in any call order
  • Seeds 7 and 8 give different fields
  • No pile inside the square around the centre: a pile is rejected when both its x and z are within 52 studs of 0, so (40, 40) fails even though it is more than 52 studs away in a straight line
  • Every pile is inside its chunk, sizes are 1 to 8, there are at most 48 per chunk, and the field is not empty

The Course Runner prints this code when the test passes.

Choose one

The level 3 test generates chunk (2, -1), then two other chunks, then (2, -1) again. What bug does that catch?

The level 3 test generates chunk (2, -1), then two other chunks, then (2, -1) again. What bug does that catch?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 11 of 11

Recap

Retiring the analogy

You no longer need “stage sets built as you walk”. Chunked generation is your code creating instances on the server near players. StreamingEnabled is the engine sending only nearby instances to each client. Client code must handle parts that are not streamed in yet, whatever created them.

Recap

  1. A seed plus a stateless hash makes generation repeatable and order-independent; math.random keeps hidden state.
  2. Noise (math.noise or value noise) gives clusters and gaps; scale the input, offset it by the seed, and avoid whole-number samples.
  3. Chunks let you build only what is near players; compute in parallel actors, then create parts in a serial phase.

Building the world near the player (chunks and StreamingEnabled) is stage sets built as you walk, until there are two crews. Your generator decides what exists on the server; StreamingEnabled separately decides which of it each client has received, so a piece can exist on the server and still be missing on a client.

Next Custom character controllers and physics

Link to this step · This confused me