Line connecting 2 gui resizing problem

You have to set the object’s position to be halfway between the wire start and current mouse position:

script.Parent.Size = UDim2.new(0,(mousePos - wireStart).Magnitude,0,20)
local centrePoint = (wireStart + mousePos) / 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, centrePoint.Y)
1 Like

it works but its on the wrong position, also the rotation doesnt match the mouse pos
image
also, is there a way to make the end part conenct to a gui?

Oh I see, try subtracting the wire’s parent’s AbsolutePosition from the position you’re trying to set it to:

script.Parent.Position = UDim2.fromOffset(centrePoint.X - wireParent.AbsolutePosition.X, centrePoint.Y - wireParent.AbsolutePosition.Y)

What do you mean?

1 Like

just like in among us, its connected to this
image
I made the same exact thing and made it draggable but idk how to connect it to there, with your help it gave me this, I removed the side so it would be visible on where it starts
image
it helped ALOT, the end is on the mouse now, but its on the wrong position

I tried making it connect to a gui and it did this

local wireEnd = script.Parent.Parent.RedConnector
local wireStart = script.Parent.Parent.RedWireStart.AbsolutePosition --absolute position in pixels

while wait() do

	local endPos = Vector2.new(wireEnd.Position.X,wireEnd.Position.Y)
	local v = endPos-wireStart
	local angle = math.deg(math.atan2(v.Y,v.X))

	script.Parent.Rotation = angle

	script.Parent.Size = UDim2.new(0,(endPos - wireStart).Magnitude,0,20)
	
	local centrePoint = (wireStart + endPos) / 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, centrePoint.Y)
	
	script.Parent.Parent.RedConnector.Rotation = script.Parent.Rotation
	
	script.Parent.Position = UDim2.fromOffset(centrePoint.X - script.Parent.Parent.AbsolutePosition.X, centrePoint.Y - script.Parent.Parent.AbsolutePosition.Y)
	
end

this is the gui I wanted it to connect, its named “RedConnector” in explorer
image
explorer:
image
the gui named "RedWire " is the line, “RedConnector” is the draggable part I wanted the line to connect to

Here’s a solution provided in the past:

ive already seen this post and when I tried it the end and start point of the line doesn’t math the position of gui

Sorry I don’t know why I didn’t see your post last night but anyway I’ll pick up where I left off. So I think what the issue is, is that you’re using the AbsolutePosition as your anchor point/the point where you want the wire’s extension to begin, instead you should try changing wireStart to be something like wire.AbsolutePosition + Vector2.new(wire.AbsoluteSize.X, wire.AbsoluteSize.Y / 2), note I’m dividing the wire’s absolute y size by 2 to ensure it’s sort of anchored to the centre of the Y axis if that makes sense.

You could also change wireStart to be the connector frame’s AbsolutePosition, think you mentioned you wanted it connected to that.

1 Like

I’m sorry, im not into maths in roblox studio so how do I put that in my script?, I haven’t tried math because I thought its gonna be alot of solving which is what I hate

Start off by changing wireStart to be wire.AbsolutePosition + Vector2.new(wire.AbsoluteSize.X, wire.AbsoluteSize.Y / 2) and see where that gets you.

OHH, it works now, TY FOR YOUR HELPP @7z99 :grin:

1 Like

I still have this problem tho


if im gonna connect it to another gui and not the mouse it do this

local mouse = script.Parent.Parent.RedConnector.Position
local wire = script.Parent.Parent.RedWireStart
local wireStart = wire.AbsolutePosition + Vector2.new(wire.AbsoluteSize.X, wire.AbsoluteSize.Y / 2) --absolute position in pixels

while wait() do

	local mousePos = Vector2.new(mouse.X,mouse.Y)
	local v = mousePos-wireStart
	local angle = math.deg(math.atan2(v.Y,v.X))

	script.Parent.Rotation = angle

	script.Parent.Size = UDim2.new(0,(mousePos - wireStart).Magnitude,0,20)
	
	local centrePoint = (wireStart + mousePos) / 2 -- this will be the "average" position which also happens to be the centre of the two points
	
	script.Parent.Parent.RedConnector.Rotation = script.Parent.Rotation
	
	script.Parent.Position = UDim2.fromOffset(centrePoint.X - script.Parent.Parent.AbsolutePosition.X, centrePoint.Y - script.Parent.Parent.AbsolutePosition.Y)
	
end

did I do something wrong with the script?
changing the position to AbsolutePosition kinda help the size but the wire doesn’t change the length anymore
image
image

I’m looking over your script but nothing really sticks out. Are there any output errors? Also just to be clear, it’s the script’s parent that you need to resize, right?

1 Like

yes, its the scripts parent I wanted to resize, and no, theres no errors, I think its the while loop thats not working properly

1 Like

Try setting the AnchorPoint property of the frame that needs to be resized to 0.5, 0.5

most all of my gui anchor points are 0.5,0.5 so the position will be the same on all devices, also, I found out that the thickness of line is based on offset which will be brocken on other sizes of screens
image
this is what it looks like on mobile

I’m a bit confused now, is the wire resizing?

And for consistent sizing on all devices, just change the size from UDim2.new(0,magnitude,0,20) to 0,magnitude,scale y,0

its resizing an constantly changing position

Wait, that isn’t what you wanted to do?

I wanted it to do that but is there a way to make the end point a gui and not the mouse?, if none ill try to find a way to do it