Issue with mining game

I’m currently working on a mining game for some reason the blocks spawn upwards sometimes. (They are only supposed to spawn, below or the sides of the destroyed block). So if im under a block and i destroy it a block will spawn above it. That is a big issue. Here is the code. Im not sure where the issue is coming from. any help is greatly appreciated!

I can show a video if what im saying isnt clear.

function createBlock(part, area, depth)
	--wait()
	local back = part.CFrame + Vector3.new(0,0,blockSize)
	local backD = math.abs(math.abs(math.floor(back.Y/blockSize))-depth)
	local bottom = part.CFrame + Vector3.new(0,-blockSize,0)
	local bottomD = math.abs(math.abs(math.floor(bottom.Y/blockSize))-depth)
	local front = part.CFrame + Vector3.new(0,0,-blockSize)
	local frontD = math.abs(math.abs(math.floor(front.Y/blockSize))-depth)
	local left = part.CFrame + Vector3.new(-blockSize,0,0)
	local leftD = math.abs(math.abs(math.floor(left.Y/blockSize))-depth)
	local right = part.CFrame + Vector3.new(blockSize,0,0)
	local rightD = math.abs(math.abs(math.floor(right.Y/blockSize))-depth)
	local top = part.CFrame + Vector3.new(0,blockSize,0)
	local topD = math.abs(math.abs(math.floor(top.Y/blockSize))-depth)
	local backA = false
	local bottomA = false
	local frontA = false
	local leftA = false
	local rightA = false
	local topA = false
	for i,v in ipairs(Airs[area]) do
		if v == back then
			backA = true
		end
		if v == bottom then
			bottomA = true
		end
		if v == front then
			frontA = true
		end
		if v == left then
			leftA = true
		end
		if v == right then
			rightA = true
		end
		if v == top then
			topA = true
		end
	end
	--wait()
	if backA == false then
		local blockName = getRandomBlock(area.Name, depth)
		local cBlock = oresSS[area]:FindFirstChild(blockName):Clone()
		cBlock.Parent = ores[area]
		cBlock.Anchored = true
		cBlock.CFrame = back
		table.insert(Airs[area],back)
	end
	if bottomA == false then
		local blockName = getRandomBlock(area.Name, depth-1)
		local cBlock = oresSS[area]:FindFirstChild(blockName):Clone()
		cBlock.Parent = ores[area]
		cBlock.Anchored = true
		cBlock.CFrame = bottom
		table.insert(Airs[area],bottom)
	end
	if frontA == false then
		local blockName = getRandomBlock(area.Name, depth)
		local cBlock = oresSS[area]:FindFirstChild(blockName):Clone()
		cBlock.Parent = ores[area]
		cBlock.Anchored = true
		cBlock.CFrame = front
		table.insert(Airs[area],front)
	end
	if leftA == false then
		local blockName = getRandomBlock(area.Name, depth)
		local cBlock = oresSS[area]:FindFirstChild(blockName):Clone()
		cBlock.Parent = ores[area]
		cBlock.Anchored = true
		cBlock.CFrame = left
		table.insert(Airs[area],left)
	end
	if rightA == false then
		local blockName = getRandomBlock(area.Name, depth)
		local cBlock = oresSS[area]:FindFirstChild(blockName):Clone()
		cBlock.Parent = ores[area]
		cBlock.Anchored = true
		cBlock.CFrame = right
		table.insert(Airs[area],right)
	end
	if topA == false then
		local blockName = getRandomBlock(area.Name, depth+1)
		local cBlock = oresSS[area]:FindFirstChild(blockName):Clone()
		cBlock.Parent = ores[area]
		cBlock.Anchored = true
		cBlock.CFrame = top
		table.insert(Airs[area],top)
	end
end

while true do
	for i = math.floor(regenTime * 60), 0, -1 do
		game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("UpdateRegenTimer"):FireAllClients(i)
		if i > 0 then task.wait(1) continue end
		
		for _, area in next, workspace.Map.Zones:GetChildren() do
			refreshing[area] = true
			local oresG = ores[area]:GetChildren()
			for i,v in pairs(game.Players:GetChildren()) do
				if v.Character and v.Character:FindFirstChild("Humanoid") and v.Character:FindFirstChild("Humanoid").Health > 0 then
					v.Character.UpperTorso.CFrame = workspace.Surface.CFrame
				end
			end
			local regenC = game.ServerStorage.RegenMines[area.Name]:Clone()
			regenC.Parent = workspace
			for i = 1,#oresG,3 do
				oresG[i]:Destroy()
				if oresG[i+1] then
					oresG[i+1]:Destroy()
				end
				if oresG[i+2] then
					oresG[i+2]:Destroy()
				end
				--task.wait()
			end
			local oresC = backup[area]:Clone()
			local oresCg = oresC:GetChildren()
			for i = 1,#oresCg,3 do
				local cOre = oresCg[i]:Clone()
				cOre.Parent = ores[area]
				if oresCg[i+1] then
					local cOre = oresCg[i+1]:Clone()
					cOre.Parent = ores[area]
				end
				if oresCg[i+2] then
					local cOre = oresCg[i+2]:Clone()
					cOre.Parent = ores[area]
				end
				--task.wait()
			end
			Airs[area] = {}
			for i,v in pairs(ores[area]:GetChildren()) do
				local pos = v.CFrame + Vector3.new(0,0,blockSize)
				local pos2 = v.CFrame + Vector3.new(0,0,-blockSize)
				local pos3 = v.CFrame + Vector3.new(-blockSize,0,0)
				local pos4 = v.CFrame + Vector3.new(blockSize,0,0)
				local pos5 = v.CFrame + Vector3.new(0,blockSize,0)
				table.insert(Airs[area],pos)
				table.insert(Airs[area],pos2)
				table.insert(Airs[area],pos3)
				table.insert(Airs[area],pos4)
				table.insert(Airs[area],pos5)
			end 
			regenC:Destroy()
			refreshing[area] = false
		end
		
		task.wait(1)
	end
end