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
Ohhhh I must have skipped over when you asked that, Iâm looking back now and you said that in the 13th post , my bad.
Yeah, you can do that. Just change mousePos
to be the end frameâs AbsolutePosition instead of the mouse.X and mouse.Y.
im a bit confused on this, do i need to do UDim2.new, UDim2.fromScale, or UDim2.fromOffset?
Youâd use UDim2.new, the first number can stay 0, second is the magnitude of the one vector subtracted from the other, scale y would be the Y scale from your start or end frames assuming you want the size to remain the same, and the fourth number can stay as 0.
it becomes as thin as you cant see it anymore
is this correct?
script.Parent.Size = UDim2.new(0,(mousePos - wireStart).Magnitude,script.Parent.Parent.RedWireStart.Size.Y,0)
update:
nvm, I just input the number by myself and not use a lot of letters to go to the start and get the Y size
local mousePos = script.Parent.Parent.RedConnector.AbsolutePosition
is this what you meanât?, after 25 post in my topic I still dont want to learn math in roblxo studio lol
Yeah, that is what I meant. (chars)
I does this, also when I used visible its of the draggable part and I dont realyl want that to happen since I want my game to be perfect and not fix it after uploading it
Can you upload a repro file? Itâs a bit hard to tell whatâs going on.
oh yeah, ive should have done that before, heres the link for the model I did, let me know if theres something wrong, heres the module for the draggable and gui collision if it show any error, placed inside replicated storage
also the position of it will change and will be this
however, using Position
instead of AbsolutePosition
helps the position, but at the same time it stretches to top left corner of the screen
I managed to make it update the size but the position became a problem once again
(dont mind if the line is thic I just forgot to change it)
(@nexos_x7 helped me with this)
local EndLine = script.Parent.Parent.RedConnector
local Line = script.Parent
local LineStart = script.Parent.Parent.RedWireStart
while wait() do
local v = EndLine.AbsolutePosition - LineStart.AbsolutePosition - (LineStart.AbsoluteSize / 2)
local Pos = EndLine.AbsolutePosition + (EndLine.AbsoluteSize / 2)
local angle = math.deg(math.atan2(v.Y,v.X))
Line.Rotation = angle
Line.Size = UDim2.new(0,v.Magnitude,0.058,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
yes exacly like that, did you use the visible
for it?, ive been thinking that might work but it might be a lil off
What I did was add a BoolValue called Drag inside your RedConnector frame, then I made the BoolValue change to true or false depending on whether you are dragging it. The updated the code to this :
local DraggableObject = require(game.ReplicatedStorage.DraggableUI)
local GuiCollisionService = require(game:GetService("ReplicatedStorage").GuiCollisionService)
local FrameDrag = DraggableObject.new(script.Parent)
local group = GuiCollisionService.createCollisionGroup()
FrameDrag:Enable()
FrameDrag.DragStarted = function()
script.Parent.Drag.Value = true
end
FrameDrag.DragEnded = function()
if GuiCollisionService.isColliding(script.Parent, script.Parent.Parent.RedWireEnd) then
script.Parent.Position = script.Parent.Parent.RedWireEnd.Position
elseif not GuiCollisionService.isColliding(script.Parent, script.Parent.Parent.RedWireEnd) then
script.Parent.Position = UDim2.new(0.157, 0,0.5, 0)
end
script.Parent.Drag.Value = false
end
Then in the other script which handles the size and position, I listened for changing of this BoolValue and created a while loop inside that function which updates the size and position.
I updated the code to this :
local mouse =game.Players.LocalPlayer:GetMouse()
local wire = script.Parent.Parent.RedWireStart
local connector = script.Parent.Parent.RedConnector
local wireStart = wire.AbsolutePosition + Vector2.new(wire.AbsoluteSize.X, wire.AbsoluteSize.Y / 2)
local Drag = script.Parent.Parent.RedConnector.Drag
Drag.Changed:Connect(function()
if not Drag.Value then return end
while Drag.Value do
task.wait()
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.058,0)
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
local EndPosition = connector.AbsolutePosition + Vector2.new(connector.AbsoluteSize.X, connector.AbsoluteSize.Y / 2)
local centrePoint = (wireStart + EndPosition) / 2
script.Parent.Size = UDim2.new(0,(EndPosition - wireStart).Magnitude,0.058,0)
script.Parent.Position = UDim2.fromOffset(centrePoint.X - script.Parent.Parent.AbsolutePosition.X, centrePoint.Y - script.Parent.Parent.AbsolutePosition.Y)
end)
the rotation doesnât math but it works, I may have to fix it a little but thank you for helping me
For that you could try doing connector.Rotation = angle
however it wouldnât be perfectly aligned
ive used
if Drag.Value == false then
script.Parent.Rotation = 0
end
and it work fine
I also might change the size of the connector to be thicker to hide some unnecessary things that shows