How do I connect my gui line to another gui and not the mouse

thaks for @7z99 for helping me fix the script, so I have this (among us easter egg)
image
it follows the mouse where ever it is, but I need to make the end of the line connect to another gui and not the mouse, but when I tried doing it it give me this
Position:


the end part is connected to top left corner of the screen
but if I use AbsolutePosition, it does this
image
heres the script:

local DragPos = script.Parent.Parent.RedConnector.AbsolutePosition --the gui I want the line to end
local wire = script.Parent.Parent.RedWireStart
local wireStart = wire.AbsolutePosition + Vector2.new(wire.AbsoluteSize.X, wire.AbsoluteSize.Y / 2)

while wait() do

	--local DragPos = Vector2.new(Drag.X,Drag.Y) --use for Position or mouse
	local v = DragPos-wireStart
	
	local angle = math.deg(math.atan2(v.Y,v.X))

	script.Parent.Rotation = angle

	script.Parent.Size = UDim2.new(0,v.Magnitude,0.058,0) --this change the size of the bar, the 0.058 is the thickness and it will stay same on every screen size
	
	local centrePoint = (wireStart + DragPos) / 2 -- this will be the "average" position which also happens to be the centre of the two points
		
	script.Parent.Position = UDim2.fromOffset(centrePoint.X - script.Parent.Parent.AbsolutePosition.X, centrePoint.Y - script.Parent.Parent.AbsolutePosition.Y)
	
end

I disabled the visible of the qui I wanted it to connect to see it clearly

i can provide a script if you are confused but what I would do is make the other Frame (the red line u need to connect to) a button so when its clicked or hovered on whichever one you want you then just set the draggable lines properties to be set onto the button

1 Like

im a bit confused, can you provide me with a script?

I know this isnt super clean code but i just made this pretty quick

local EndLine = script.Parent.EndLine
local Line = script.Parent.Line
local LineStart = script.Parent
local Mouse = game.Players.LocalPlayer:GetMouse()
local Completed = false

EndLine.MouseButton1Click:Connect(function()
	Completed = true
end)

while wait() do
	local v
	local Pos
	
	-- Sets the v to the correct value depending on the completion status
	if not Completed then
		v = Vector2.new(Mouse.X, Mouse.Y) - LineStart.AbsolutePosition - (LineStart.AbsoluteSize / 2)
		Pos = Mouse
	else
		v = EndLine.AbsolutePosition - LineStart.AbsolutePosition - (LineStart.AbsoluteSize / 2)
		Pos = EndLine.AbsolutePosition + (EndLine.AbsoluteSize / 2)
	end

	local angle = math.deg(math.atan2(v.Y,v.X))
	Line.Rotation = angle
	Line.Size = UDim2.new(0,v.Magnitude,0.5,0)
	Line.Position = UDim2.new(0, ((((LineStart.AbsolutePosition.X - (LineStart.AbsoluteSize.X / 2)) - Pos.X) * -1) / 2) - (Line.AbsoluteSize.X / 2), 0, ((((LineStart.AbsolutePosition.Y - (LineStart.AbsoluteSize.Y / 2)) - Pos.Y) * -1) / 2) - (Line.AbsoluteSize.Y / 2))
end

image

image

image

1 Like

If you’re still encountering this problem, I posted a forum about this issue maybe it’ll help:
Here’s the link: How to connect two UI objects with a line