How do I make a line between two frames?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to change the size of the frame to the position of the farthest frame away no matter what size.

  2. What is the issue? I am unsure how to do this.

  3. What solutions have you tried so far? I have done some searching around and I am overall not sure how to achieve this. I have come up with a few solutions that do not work.

I am trying to determine how far 2 frames are from each other and then making a line between them matching them up no matter what size they are but I cannot seem to achieve this. Can I get some help?


local Frame1 = Instance.new("Frame")
Frame1.Position = UDim2.new(0,0,0.05,0)
Frame1.Size = UDim2.new(0.1,0,0.07,0) or UDim2.new(0.15,0,0.07,0)
Frame1.Name = "Start"
Frame1.Parent = script.Parent

local Line = Instance.new("Frame")
Line.Name = "Line"
Line.Position = UDim2.new(0.5,0,0.05,0)
Line.Size = UDim2.new(0.1,0,0.07,0)
Line.BackgroundTransparency = 0.7
Line.Parent = Frame1

local Frame2 = Instance.new("Frame")
Frame2.Name = "Finish"
Frame2.Position = UDim2.new(0.5,0,0.05,0)
Frame2.Size = UDim2.new(0.1,0,0.07,0)
Frame2.Parent = script.Parent

local distance = (Frame2.AbsolutePosition - Frame1.AbsolutePosition).magnitude
print(distance)

--Move line to distance.
Line:TweenSize(UDim2.new(distance, 0, Line.Size.Y.Scale, 0), "Out", "Linear", 0.16) 

--??
1 Like

Hmmmm maybe it is too hard to do? I am not sure.

This is not so well explained. Can you explain what you are trying to achieve more detailed?

You’re using the distance as X’s Scale component, while AbsolutePosition is based on an exact number of pixels (offset). Try using the distance as the offset component of its size instead:
Line:TweenSize(UDim2.new(0, distance, Line.Size.Y.Scale, 0), "Out", "Linear", 0.16)

2 Likes

I can’t use offset because I need the frame to fit all screens. So how could i get it to fit the screen without using offset?

Once you get it in offset, you can divide the number of pixels for the distance by the number of pixels in the AbsoluteSize of the line’s Parent (Frame1) to convert it to scale.

2 Likes

Is there any chance I could get an example of that? I am not quite sure.

Instead of Line:TweenSize(UDim2.new(0, distance, Line.Size.Y.Scale, 0), "Out", "Linear", 0.16), it’d be something like Line:TweenSize(UDim2.new(distance / Frame1.AbsoluteSize.X, 0, Line.Size.Y.Scale, 0), "Out", "Linear", 0.16)

5 Likes

Thank you for the help. That is just what I needed.