Problem with trying to connect parts by resizing part

the problem is that if the parts are different size on the direction axis, then it will get the wrong size.

local part1 = workspace.part1 
local part2 = workspace.part2

local Direction = Vector3.new(0, 1, 0)
local DirectionValue = Direction.X + Direction.Y + Direction.Z
local InversedDirection = (Direction - Vector3.new(DirectionValue, DirectionValue, DirectionValue))
InversedDirection = Vector3.new(math.abs(InversedDirection.X), math.abs(InversedDirection.Y), math.abs(InversedDirection.Z))

local difference = part1.Position - part2.Position
part1.Size = difference + (part2.Size * InversedDirection)
part1.Position = part2.Position + (Direction * part2.Size/2) + (Direction * part1.Size/2)

same size:

different size:

Can you explain what is going on?