Terrain generation is generating in a line but I dont see why

Im trying to create a terrain generation script which ill later expand into 3d perlin noise but something is not right


It comes out in 1 line but this is the script

local Xsize = 64
local Zsize = 64
local Ysize = 32
local blockSize = 4
local seed = math.random(1,1000000)
local smoothness = 30
local noiseScale = 20
print("Seed: " .. seed)

local function round(a,b)
return math.floor(a/b)*b
end

for x=1,Xsize do
for y=1,Ysize do
for z=1,Zsize do

        local noise = math.noise(x / smoothness, y / smoothness, z / smoothness) * noiseScale
        local b = Instance.new("Part", workspace)
        b.Size = Vector3.new(blockSize, blockSize, blockSize)
        b.Anchored = true
        b.Position = Vector3.new(x*blockSize, round(noise,blockSize), z*blockSize)
        wait()
        
    end
end

end

I dont see anything wrong i tried anything that comes to mind but nothing works. Can someone tell me what im missing?

--Tables
local TerrainParts = {}

--Variables
local xLength = 50
local zLength = 40
local partOffset = 10
local partNumber = 1

for i=1, xLength do
    TerrainParts[i] = {i}
    
    for j=1, zLength do
        TerrainParts[i][j] = i 
        local part = Instance.new("Part")
        part.Parent = game.Workspace.TerrainParts

        part.Name = partNumber
        part.Anchored = true
        part.Position = Vector3.new(j * partOffset, -10, i * partOffset)
        part.Size = Vector3.new(10,15,10)
        part.BrickColor = BrickColor.new("Bright green")
        part.TopSurface = "Smooth"
        partNumber += 1
    end
    partNumber += 1
end

You can try something like this. Looking through your code, I think the error is in your for loop. The code above will give a 50x1x40 terrain dimension. You can probably figure out how to add the height (Y) by looking through it.

thanks! u reminded me that i need only X and Z loops and no Y loop

1 Like