So I made a two different ways of dragging different UI elements but the problem is that when I put the GUI Object in a frame, it messes up where the frame is relative to the mouse
Why is this happening? Do I have to take in account the Absolute Size of the frame that the GUI Object is inside of when setting the position of the frame relative to the mouse position?
if frame.Parent:IsA("GuiObject") then
frame.Position = UDim2.new(0, mouse.X-frame.Parent.AbsolutePosition.X, 0, mouse.Y-frame.Parent.AbsolutePosition.Y)
else
frame.Position = UDim2.new(0,mouse.X,0,mouse.Y)
end
If the frame is inside e.g. a ScreenGui, it uses your working code, since you say it works that way.
If the frame is inside a frame (or any other gui object), it offsets itself by that object’s position (the draggable object’s position is relative to the position of the parent frame while the mouse position isn’t).