Voxel generation

When I set ‘d’ (guessing that’s density?) to > 0 instead of >= 0, it still generated the blocks below other blocks

function generateTerrain(mapSize)
	local densityMap = {}
	for x = 1, mapSize do
		for y = 1, mapSize/2 do
			for z = 1, mapSize do
				mapSet(densityMap, x, y, z, density(x/mapSize, y/(mapSize/2), z/mapSize))
			end
		end
	end
	
	for x = 1, mapSize do
		for y = 1, mapSize/2 do
			for z = 1, mapSize do
				local d = mapGet(densityMap, x, y, z)
				if d > 0 then
					local block = script.Block:Clone()
					block.CFrame = CFrame.new(x * 4, y * 4, z * 4)
					block.BrickColor = BrickColor.Green()
					block.Parent = game.Workspace
				end
			end
		end
		wait()
	end
end

Not sure what ‘lower_threshold’ actually equals? And another question that’s popped up. Increasing sizes. Atm it seems like a constant ‘size’ in terms of height. Is there a way I can add a variable or something to make it so some areas are really flat, while others are quite hilly/high