I made this and it doesn't work, any ideas? Its supposed to tween the button to the GUI frame that it is hovering over
script.Parent.DragStopped:connect(function() for i, v in pairs(script.Parent.Parent.Parent:GetChildren())do if script.Parent.Position == v.Position then script.Parent:TweenPosition(v.Position + UDim2.new(.05, 0, .05, 0), "InOut", "Sine", .5, true) else script.Parent:TweenPosition(UDim2.new(.05, 0, .05, 0), "InOut", "Sine", .5, true) script.Parent.Draggable = true end end end) script.Parent.MouseButton1Click:connect(function() script.Parent.Draggable = true end)
Any ideas?
Your problem is on this line:
if script.Parent.Position == v.Position then
For this to be true, the gui object you're dragging has to be pixel perfect over the one you want to drag it t, assuming they're even in the exact same Frame!
After that, if it doesn't loop on the Frame you're trying to drag it on to dead last, it'll go back to (.05, 0, .05, 0) anyway.
Try this code:
script.Parent.DragStopped:connect(function() local target for i, v in pairs(script.Parent.Parent.Parent:GetChildren())do local sPos = script.Parent.AbsolutePosition local vPos = v.AbsolutePosition local vSize = v.AbsoluteSize if sPos.X >= vPos.X and sPos.X < vPos.X + vSize.X and sPos.Y >= vPos.Y and sPos.Y < vPos.Y + vSize.Y then target = v break end end if target then script.Parent:TweenPosition(target.Position + UDim2.new(.05, 0, .05, 0), "InOut", "Sine", .5, true) else script.Parent:TweenPosition(UDim2.new(.05, 0, .05, 0), "InOut", "Sine", .5, true) script.Parent.Draggable = true end end) script.Parent.MouseButton1Click:connect(function() script.Parent.Draggable = true end)