Is there a way to convert mouse position to scale?

Ok so when I usually make “Hover GUIs or “Cross hairs” I like most people would write…

-Example-
Local Gui = [path to Gui]

Local Player = game.Players.localPlayer
Local Mouse = Player:GetMouse()

function MoveMouse()
Gui.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
end

Mouse.Moved:Connect(MoveMouse)

But the problem of doing it that way is

Your forced to use Offset, which doesn’t scale on all screens

Is there an alternative method of some sort I can use?!

1 Like

I would imagine this would still work on all screens, because if the screen size changes, the mouse position will only ever be on the screen it’s being used on.

You can generate the scale values yourself by dividing the position by the screen size.

2 Likes

No I tried it multiple times it doesn’t scale because your using offset…

You can do this to divide the screen size by the mouse position.
UDim2.new(Mouse.X/Mouse.ViewSizeX, 0, Mouse.Y/Mouse.ViewSizeY, 0)

12 Likes

I thought about that xD, but my pc died before I could try it (probably works)

Sorry for the bump, but the ViewSizeY seems like it doesn’t scale properly. It goes past 1 when the mouse is near the bottom of the screen, and changing the screen size and putting my mouse in the same spot shows slightly different values.

2 Likes