I’m a little late to the party but,
I also just want to note, the rotation of ‘atan2((y1-y2),(x1-x2))’ should be converted to degrees with the ‘math.deg()’ function. Took me way to long to figure that out
Anyway, I made a simple function to draw a line between 2 points using the logic @scotch101tape said (Point A and Point B should be Vector2’s in pixels from the top left corner of the screen, aka the AbsolutePosition of a UI object)
local function DrawLine(PointA, PointB, Parent)
local Distance = math.sqrt(math.pow(PointA.X-PointB.X, 2) + math.pow(PointA.Y-PointB.Y, 2))
local Center = Vector2.new((PointA.X + PointB.X)/2, (PointA.Y + PointB.Y)/2)
local Rotation = math.atan2(PointA.Y - PointB.Y, PointA.X - PointB.X)
local LineThickness = 4
local Line = Instance.new("Frame")
Line.Size = UDim2.new(0, Distance, 0, LineThickness)
Line.AnchorPoint = Vector2.new(0.5,0.5)
Line.Position = UDim2.new(0, Center.X, 0, Center.Y)
Line.Rotation = math.deg(Rotation)
Line.Parent = Parent
end