I am trying to make a terrain generation script that uses math.noise. I tried making the script place gray blocks under the top green blocks, but for some reason it seems that the green blocks aren’t on top and I really don’t know why.
Here is the script:
for x = 1,25 do
for z = 1,25 do
local p = game:GetService("ReplicatedStorage").G:Clone()
p.Parent = workspace
p.Anchored = true
p.Size = Vector3.new(3,3,3)
p.TopSurface = Enum.SurfaceType.Smooth
p.BackSurface = Enum.SurfaceType.Smooth
p.Color = Color3.fromRGB(52, 142, 64)
local height = (math.noise(x / 20, seed, z / 20) + 2) * 50
p.Position = Vector3.new(3*x,height-height%3,3*z)
if p.Position.Y < 120 then
p:Destroy()
end
if p.Position == 120 then
p.Color = Color3.fromRGB(0,0,0)
p.Name = "Baseplate"
end
local am = 3
for i = 1,25 do
local p2 = game:GetService("ReplicatedStorage").Stone:Clone()
p2.Parent = workspace.blocks
p2.Position = Vector3.new(p.Position.X,p.Position.Y-am,p.Position.Z)
if p2.Position.Y < 120 then
p2:Destroy()
elseif p2.Position.Y == 120 then
p2.Color = Color3.fromRGB(0,0,0)
p2.Name = "Baseplate"
end
am = am - 3
end
wait()
end
end
“G” is a green block in replicated storage
“Stone” is the gray block in replicated storage
Here is the result:
The only green I see is a small amount on the bottom.

So why is the script not putting those green blocks on top and how do I make it do so?