Drawing A Line Between Two GUI Points In Scale

So heres your issue, you didn’t actually convert the starting positions back into offset values, and VineyardVine was using the exact opposite of that, however he was right.

local function DrawPath(Line, P1, P2)
	local Size = workspace.CurrentCamera.ViewportSize
	local startX, startY = P1.Position.X.Scale*Size.X, P1.Position.Y.Scale*Size.Y
	local endX, endY = P2.Position.X.Scale*Size.X, P2.Position.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

Now the points you input are scale based however the actual line will not be scale but offset, however this won’t matter since it’s all relative anyways.

The above code is your solution, ive tried it at a billion different angles.

27 Likes