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

How do I remove this offset the frame has from the mouse?

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Move:Connect(function()
	script.Parent.Frame.Position = UDim2.new(mouse.X/1000,0,mouse.Y/1000,0)
	print(mouse.X/1000)
end)

If you paste this into a localscript, the frame will have an offset from the mouse. How do I fix it so that the frame is where the mouse is, with no offset?

2 answers

✓ Accepted answer

You can use ViewSizeX and ViewSizeY to get the dimensions of the players' screen/window.

local mouse = game.Players.LocalPlayer:GetMouse()
local GS = game:GetService("GuiService")
mouse.Move:Connect(function()
    script.Parent.Frame.Position = UDim2.new(mouse.X/mouse.ViewSizeX,0,mouse.Y/(mouse.ViewSizeY + GS:GetGuiInset().Y),0)
    print(mouse.Y/mouse.ViewSizeY)
end)

You can also get the size of the topbar using the GuiService.

You can just do script.Parent.Frame.Position = UDim2.new(0, mouse.X, 0, mouse.Y);.

There's no need for the calculations.

1 comment

0

Make sure you have no GUI scaling component! This messes up the position very weirdly.

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