-- Configuration
local partSize = Vector3.new(4, 4, 4)
local areaSize = Vector3.new(40, 40, 8) -- Increased area size to accommodate 8 layers
local initialPosition = Vector3.new(0, 2, 0) -- Start height at 2
local spawnHeight = 9.99 -- Height for the spawn location
local heightChances = {
{height = 30, chance = 0.1, blockType = "GrassBlock"}, -- Height 30 with 10% chance of GrassBlock
{height = 26, chance = 0.9, blockType = "GrassBlock"}, -- Height 26 with 90% chance of GrassBlock
{height = 22, chance = 1, blockType = "DirtBlock"}, -- Height 22 and below always DirtBlock
{height = 18, chance = 1, blockType = "DirtBlock"}, -- Height 18 with 10% chance of GrassBlock
{height = 14, chance = 1, blockType = "DirtBlock"}, -- Height 14 with 10% chance of GrassBlock
{height = 10, chance = 1, blockType = "DirtBlock"}, -- Height 10 with 10% chance of GrassBlock
{height = 6, chance = 1, blockType = "DirtBlock"}, -- Height 6 with 10% chance of GrassBlock
{height = 2, chance = 1, blockType = "DirtBlock"}, -- Height 2 always DirtBlock
}
local delayBetweenParts = 0.00000000000000000000000000000001 -- Delay in seconds for parts to appear
-- Parent folder for the generated parts
local parentFolder = game.Workspace.Assets.Land
-- Function to create a single part with a unique name and color
local function createPart(x, y, height, blockType)
local part = game.ReplicatedStorage[blockType]:Clone()
part.Size = partSize
part.Position = initialPosition + Vector3.new(x * partSize.X, height, y * partSize.Z)
part.Parent = parentFolder
part.Name = "Part_" .. x .. "_" .. y .. "_" .. height
return part
end
-- Function to generate the area of parts
local function generateArea()
-- Create the spawn location at the specified height
local spawnX = math.random(1, areaSize.X)
local spawnY = math.random(1, areaSize.Y)
local spawnPosition = initialPosition + Vector3.new(spawnX * partSize.X, spawnHeight, spawnY * partSize.Z)
-- Create the spawn location
local spawnLocation = Instance.new("SpawnLocation")
spawnLocation.Position = spawnPosition
spawnLocation.Parent = parentFolder
spawnLocation.Name = "SpawnLocation"
spawnLocation.Size = partSize
spawnLocation.Anchored = true
for x = 1, areaSize.X do
for y = 1, areaSize.Y do
local height = math.random(1, 100) -- Generate a random number from 1 to 100
local selectedHeight = 2 -- Default to height 2 (DirtBlock)
for _, data in pairs(heightChances) do
if height <= (data.chance * 100) then
selectedHeight = data.height
break
end
end
createPart(x, y, selectedHeight, "DirtBlock")
wait(delayBetweenParts)
end
end
end
-- Call the function to start generating the area
generateArea()
I’m using custom parts to generate minecraft-like land. The code is making dirt blocks at the very top, and not generating the height below 22…and height 22, 26 and 30 are dirt blocks even know they are supposed to be grass.