Problem with uneven values in placement system

Hello. Recently I have been creating a game where you build blocks with a color and a size value. The problem is, my block positioning system doesn’t account for uneven values.

–This works:
image

–This doesn’t work:
image

–What I want to happen
image

–What happens

image

image

image

–The code that is causing this

      
		local xDif = 0
		local yDif = 0
		local zDif = 0

		local x = 0
		local y = 0
		local z = 0
		
		if surface == Enum.NormalId.Top then
			yDif = trackingPart.Size.Y
		elseif surface == Enum.NormalId.Bottom then
			yDif = -trackingPart.Size.Y
		elseif surface == Enum.NormalId.Front then
			zDif = -trackingPart.Size.X
		elseif surface == Enum.NormalId.Back then
			zDif = trackingPart.Size.X
		elseif surface == Enum.NormalId.Right then
			xDif = trackingPart.Size.Z
		elseif surface == Enum.NormalId.Left then
			xDif = -trackingPart.Size.Z
		end
		
		local X = trackingPart.Size.X
		local Y = trackingPart.Size.Y 
		local Z = trackingPart.Size.Z

		local roundX = math.round(X) / 2
		local roundY = math.round(Y) / 2
		local roundZ = math.round(Z) / 2

		if target.Name == "Block" then
			x = math.round(target.Position.X / roundX) * roundX + xDif
			y = math.round(target.Position.Y / roundY) * roundY + yDif
			z = math.round(target.Position.Z / roundZ) * roundZ + zDif
		else
			x = math.round(Mouse.Hit.Position.X / roundX) * roundX
			y = math.round(target.Position.Y / roundY)/4 * roundY + yDif
			z = math.round(Mouse.Hit.Position.Z / roundZ) * roundZ
		end

I think that it is something to do with x, y, z Dif.

Any help is appreciated. Thanks!