How do I get the position of the player's mouse relative to the center of the screen?

Basically, I made a version of this myself but it totally decided it wasn’t going to work as soon as I switched PCs (I know, it’s the amount of pixels per screen.)

But, I want it to work on EVERY screen.

So, since ROBLOX measures position of the mouse based on the top left corner, how do I offset it based on monitor size?

I basically just want to know how to get the position of the mouse relative to the center of the screen.

Assuming you mean the position of the mouse on the screen as a Vector2, you can get the screen size from the camera object.

local camera = workspace.CurrentCamera

local screenSize = camera.ViewportSize
local screenCenter = (screenSize * 0.5)

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

local function getRelativePos()
	return (Vector2.new(mouse.X, mouse.Y) - screenCenter)
end
3 Likes

No yeah, I was talking about Vector2, sorry.

I put my mouse at roughly the center of the screen and it still has an offset.

(I set it to print out the getRelativePos() result)

Nevermind, calculated it on the client and sent it over by variable instead, thank you so much.