So I want to make this script so when you hold down on a gui it follows the position of the mouse. The problem is when I tried this with taking the main position and offsetting it, it has another little offset when it tries following my mouse.
local origpos = obj.Box.AbsolutePosition
repeat
local desiredPos = Vector2.new(mousepos.X,mousepos.Y)
local relativePosition = desiredPos - origpos
obj.Box.Position = UDim2.fromOffset(relativePosition.X,relativePosition.Y)
wait()
until down == false
local Player = game.Players.LocalPlayer
local mouse = player:GetMouse()
-- now anchor your gui object 0.5,0.5 this is makes it more simple to center it.
guiObject.Position = Udim2.new(0, mouse.X - "parent of guiObject".AbsolutePosition.X, mouse.Y - "parent of guiObject".AbsolutePosition.Y, -20 -- to offset it 20 pixels above the mouse icon.)
That’s how you center it as for holding down on the gui just use math.clamp to stay within the bounds of the frame and you should be good.
The gui can already follow the mouse, it just has an offset. Also I tried that and it does the exact same thing. Is the offset something to do with the UIGridLayout and other guis?
Also, I don’t need it to stay within the frame, just to follow the mouse.
If you tried the example I gave then it probably has something to do with the uigridlayout because to follow the mouse the code I gave should work. If it’s doing the exact same thing like you stated then delete the grid layout is all I can say.
I figured out that if I clone it and set its parent to screengui while maintaining the absolute size, I can set the position of the mouse. For some reason I had to subtract 0.075 scale to make it centered.