Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

Ad
Log in to vote
0
Answered by
Nowaha 459 Moderation Voter
4 years ago
Edited 4 years ago

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

There's no need for the calculations.

0
Make sure you have no GUI scaling component! This messes up the position very weirdly. Nowaha 459 — 4y

Answer this question