Why is the position of the buttons offsetted when drawing a line?

I’m making a node-based editor where the user can click on a button parented to the node to connect it to another one (shown in the video). But when a node is connected to another, the start and end points of the line showing connection are a bit off. How could I fix this?

Video Example:

Code for drawing the line:

function drawPath(Line, P1, P2)

local Size = workspace.CurrentCamera.ViewportSize

local startX, startY = P1.X.Scale*Size.X, P1.Y.Scale*Size.Y

local endX, endY = P2.X.Scale*Size.X, P2.Y.Scale*Size.Y

local startVector = Vector2.new(startX, startY)

local endVector = Vector2.new(endX, endY)

local Distance = (startVector - endVector).Magnitude

Line.AnchorPoint = Vector2.new(0.5, 0.5)

Line.Size = UDim2.new(0, Distance, 0, 5)

Line.Position = UDim2.new(0, (startX + endX) / 2, 0, (startY + endY) / 2)

Line.Rotation = math.atan2(endY - startY, endX - startX) * (180 / math.pi)

end

		local mouse = game.Players.LocalPlayer:GetMouse()
		local mousePositionScale = UDim2.new((mouse.X-script.Parent.Pan.Position.X.Offset)/mouse.ViewSizeX,0,(mouse.Y-script.Parent.Pan.Position.Y.Offset)/mouse.ViewSizeY,0)
		local pos = UDim2.new((connect.AbsolutePosition.X-script.Parent.Pan.Position.X.Offset)/mouse.ViewSizeX,0,(connect.AbsolutePosition.Y-script.Parent.Pan.Position.Y.Offset)/mouse.ViewSizeY,0)
		connect.BackgroundTransparency = 0
		drawPath(Line,pos,mousePositionScale)

The size of the parent of the line is UDim2.new(3,0,3,0) and it can be panned.

Not 100% sure but it could have something to do with the anchor point of the node instead of the line.

What should I change its Anchor Point to?

Try {0.5,0.5}
This will place the anchor point in the middle of the object.

I tried this. I’m not having any problems with the X Position but the Y Position is still off