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)
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
it helped ALOT, the end is on the mouse now, but its on the wrong position
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
explorer:
the gui named "RedWire " is the line, “RedConnector” is the draggable part I wanted the line to connect to
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.
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
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
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?
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