Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

GUI Inventory Help?

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?

1 comment

0

Thank you so much! :D

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.