PcoWSkbVqDnWTu_dm2ix
The Developer Hub is now deprecated and information on this page may no longer be accurate. To see our new and improved documentation, please click here. You can read more about the future of documentation here.
Collapse Sidebar

Y

Mouse

int

The Y property describes the vertical 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/X 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.


Code Samples


Normalized Mouse Position

This code sample shows how you can create a DataType/Vector2 representing the Mouse object’s position on screen (Mouse/X|X and Mouse/Y|Y) and the size of the screen itself (Mouse/ViewSizeX|ViewSizeX and 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 Mouse/Move|Move event.