#3309 Roblox Script for 10x10 Grid of Cubes and Streets

#3309 Roblox Script for 10x10 Grid of Cubes and Streets

#3309 Provide a Roblox script to create a small town composed of a 10 x 10 grid of various size cubes, separated by streets

Below is a complete Lua script you can drop into ServerScriptService (or as a Script under Workspace) to procedurally generate a 10×10 grid of randomly-sized cube “buildings” separated by street parts.

-- Parameters
local gridSize = 10 -- number of buildings per row/column local streetWidth = 10 -- width of each street (in studs) local blockSpacing = 40 -- total cell size (building + street) local minCubeSize = 10 -- smallest building edge length local maxCubeSize = blockSpacing - streetWidth -- largest building edge length local workspace = game:GetService("Workspace") -- (Optional) clear previously generated town for _, obj in ipairs(workspace:GetChildren()) do if obj.Name:match("^Building_%d+_%d+$") or obj.Name:match("^Road_[HV]_%d+$") then obj:Destroy() end end -- Compute offset to center the town at the world origin local offset = (gridSize - 1) * blockSpacing / 2 -- Generate Buildings for x = 0, gridSize - 1 do for z = 0, gridSize - 1 do local size = math.random(minCubeSize, maxCubeSize) local bld = Instance.new("Part") bld.Name = ("Building_%d_%d"):format(x+1, z+1) bld.Shape = Enum.PartType.Block bld.Anchored = true bld.Size = Vector3.new(size, size, size) bld.Position = Vector3.new( x * blockSpacing - offset, size / 2, z * blockSpacing - offset ) bld.BrickColor = BrickColor.Random() bld.Parent = workspace end end -- Generate Horizontal Streets for z = 0, gridSize do local road = Instance.new("Part") road.Name = ("Road_H_%d"):format(z) road.Anchored = true road.Size = Vector3.new(gridSize * blockSpacing, 1, streetWidth) road.Position = Vector3.new( 0, 0.5, z * blockSpacing - offset - streetWidth/2 ) road.BrickColor = BrickColor.new("Really black") road.Parent = workspace end -- Generate Vertical Streets for x = 0, gridSize do local road = Instance.new("Part") road.Name = ("Road_V_%d"):format(x) road.Anchored = true road.Size = Vector3.new(streetWidth, 1, gridSize * blockSpacing) road.Position = Vector3.new( x * blockSpacing - offset - streetWidth/2, 0.5, 0 ) road.BrickColor = BrickColor.new("Really black") road.Parent = workspace end

How it works

  1. Parameters

    • gridSize: number of blocks along each axis (10).

    • streetWidth: width of streets in studs.

    • blockSpacing: total cell size (building footprint + street).

    • minCubeSize / maxCubeSize: range for random cube dimensions.

  2. Clearing

    • Optionally removes any previously generated parts named Building_* or Road_H_*/Road_V_*.

  3. Centering

    • Calculates an offset so the entire town is centered at (0,0,0).

  4. Building Generation

    • Loops over a 10×10 grid, randomizes a cube size, and positions each cube so it sits on the “ground.”

    • Uses BrickColor.Random()—feel free to replace with a fixed palette.

  5. Street Generation

    • Creates horizontal and vertical road parts between the buildings, colored black and sitting just above ground level.


Customization Tips

  • Density & Spacing: Tweak blockSpacing and streetWidth for wider/narrower roads or tighter building layouts.

  • Building Styles: Swap out BrickColor.Random() for specific BrickColor.new("Bright blue"), or change Part.Material (e.g. Concrete).

  • Height Variation: If you’d rather have taller skyscrapers, decouple height from width/depth by setting part.Size = Vector3.new(w, randomHeight, d) instead of cubes.

Simply run this script in Play mode to watch your small, procedural town spring to life!


From <https://chatgpt.com/>  ChatGPT 4o-mini-high

Comments

Popular posts from this blog

#2892 Example of ChatGPT o1 Prompt

#3105 Federal and State Spending Idiocy