How can I generate terrain and generate structures that do not interfere with other structures?

I tried creating structures with perlin noise, but they generate above the ground and interfere with each other.

There is script:

local Replicated = game:GetService("ReplicatedStorage")
local Terrain = workspace:WaitForChild("Terrain")

local X = 100
local Z = 100

local XCenter = (X * 5) / 2
local ZCenter = (Z * 5) / 2

local RandomNoiseParametr = math.random(10,20)

local grid = {}

for x = 1, X do
	grid[x] = {}
	
	for z = 1, Z do
		
		grid[x][z] = math.noise(x/RandomNoiseParametr, z/RandomNoiseParametr) * 15
	end
end

local GenerationFolder = Instance.new("Folder")
GenerationFolder.Name = "TerainGenerationFolder"
GenerationFolder.Parent = Terrain

local HouseGenerationFolder = Instance.new("Folder")
HouseGenerationFolder.Name = "HouseGenerationFolder"
HouseGenerationFolder.Parent = Terrain

local preX = 0
local preZ = 0

for x = 1, X do
	for z = 1, Z do
		local part = Instance.new("Part")
		part.Anchored = true
		part.Position = Vector3.new((x*5) - XCenter, grid[x][z], (z*5) - ZCenter)
		part.Size = Vector3.new(5, 30, 5)
		part.Color = Color3.fromRGB(111, 126, 62)
		part.Material = Enum.Material.Grass
		part.Parent = GenerationFolder
		
		Terrain:FillBlock(CFrame.new((x*5) - XCenter, grid[x][z], (z*5) - ZCenter), Vector3.new(5, 30, 5), Enum.Material.Grass)
		
		if preX + math.random(20, 21) < x and preZ + math.random(20, 21) < z then
			local CloneHouse = Replicated:WaitForChild("House"):Clone()
			local CFram = CFrame.new((x*5) - XCenter, (grid[x][z] * 1) + CloneHouse.PrimaryPart.Size.Y, (z*5) - ZCenter)
			
			CloneHouse:PivotTo(CFram)
			
			CloneHouse.Parent = HouseGenerationFolder
			
			CloneHouse.PrimaryPart:Destroy()
			
			preX = x
			preZ = z
			
		end
	end
end