Terrain generation issue

I wanna remove artifacts that are made during terrain generation and face calculations.

I want them to merge together and be hollow than to be individual and show faces inside terrain.

local function createChunk(cX, cZ)
	local grid = {}
	
	local chunkThreadStarted = os.time()
	local chunkThread
	chunkThread = coroutine.create(function()
		for y = 1, Y do
			game:GetService('RunService').Heartbeat:Wait()
			
			if yModels[y] == nil then yModels[y] = Instance.new('Model') yModels[y].Parent = workspace yModels[y].Name = y end
			if grid[y] == nil then grid[y] = {} end

			local thread
			thread = coroutine.create(function()
				for x = 1, X do
					if grid[y][x] == nil then grid[y][x] = {} end

					for z = 1, Z do
						local block = getBlock(x + (cX * X), y, z + (cZ * Z))
						grid[y][x][z] = block
						if block ~= nil then
							block.Position = Vector3.new((x+(cX*X)) * 4, (y * 4) - ((Y/2) * 4), (z+(cZ*Z)) * 4)
						end
					end
				end
				coroutine.yield(thread)
			end)
			coroutine.resume(thread)
		end

		for y = 1, Y do
			game:GetService('RunService').Heartbeat:Wait()
			local xGrid = grid[y]

			local thread
			thread = coroutine.create(function()
				for x, zGrid in xGrid do
					for z, block in zGrid do
						local directionsFacingAir = {}

						local inView = false
						for direction, vector in directions do
							if grid[y + vector.Y] and grid[y + vector.Y][x + vector.X] and grid[y + vector.Y][x + vector.X][z + vector.Z] then
								-- Adjacent block
							else
								inView = true
								directionsFacingAir[direction] = true
							end
						end

						if inView then 
							block.Parent = yModels[y]
							for direction in directionsFacingAir do
								local texture = stone[direction]:Clone()
								texture.Parent = block
							end
						else
							block.Parent = nil
							for _, texture in block:GetChildren() do
								texture:Destroy()
							end
						end
					end
				end
				coroutine.yield(thread)
			end)
			coroutine.resume(thread)
		end
		
		print('Chunk \'x:', cX .. ', z:', cZ .. '\' finished in', (os.time() - chunkThreadStarted) .. 'ms')
		coroutine.yield(chunkThread)
	end)
	coroutine.resume(chunkThread)
end