This property can only be read from. Attempting to write to it will cause an error.
This item is not replicated across Roblox’s server/client boundary.
When detecting changes in the mouse’s position on-screen, it is recommended that you use
UserInputService/InputChanged, which both describe the position of the mouse using the
DataType/Vector3) of an
InputObject, instead of using this and related properties.
The X property describes the horizontal component of the mouse’s position on the screen. The position is measured in pixels relative to the top left corner, under the topbar. This property can be used in conjunction with
Mouse/Y to produce a
DataType/Vector2 representing the mouse’s position:
local position = Vector2.new(mouse.X, mouse.Y)
This property does not fire
Instance/Changed|Changed or the signal returned from
Instance/GetPropertyChangedSignal|GetPropertyChangedSignal. Use the
Mouse/Move event instead.
Normalized Mouse Position
This code sample shows how you can create a
DataType/Vector2 representing the
Mouse object’s position on screen (
Mouse/Y|Y) and the size of the screen itself (
Mouse/ViewSizeY|ViewSizeY). Using these, you can normalize the position of the mouse on-screen such that the top-left just under the topbar maps to (0, 0) and the bottom-right maps to (1, 1). This normalized position is calculated and printed as the mouse moves using the
-- Note: You should use ContextActionService or UserInputService instead of -- the Mouse object for accomplishing this task. local player = game.Players.LocalPlayer local mouse = player:GetMouse() local function onMouseMove() -- Construct Vector2 objects for the mouse's position and screen size local position = Vector2.new(mouse.X, mouse.Y) local size = Vector2.new(mouse.ViewSizeX, mouse.ViewSizeY) -- A normalized position will map the top left (just under the topbar) -- to (0, 0) the bottom right to (1, 1), and the center to (0.5, 0.5). -- This is calculated by dividing the position by the total size. local normalizedPosition = position / size print(normalizedPosition) end mouse.Move:Connect(onMouseMove)