Mouse
Mouse : Instance
Overview
The Mouse class offers a range of properties and methods for interacting with the player's mouse. It is often used for tasks such as detecting where the mouse is pointing in the game world, changing the appearance of the cursor, or implementing click-based mechanics.
Description
The Mouse class provides developers with tools to interact with the player's mouse input. It is primarily used to detect the mouse's position, raycast into the 3D world, and handle mouse-related events like clicks. The Mouse object is accessible via Player:GetMouse() and is commonly used in local scripts for gameplay mechanics or UI interactions. However, newer projects are encouraged to use UserInputService for more robust input handling.
Properties
Hit
CFrame
Hit represents the CFframe of an object in the 3D space that the mouse is pointing to.
Code Samples
Origin
CFrame
Origin represents the CFrame of the mouse's position in 3D space relative to the Workspace and is positioned at the Workspace.CurrentCamera oriented toward the Mouse's 3D position.
Code Samples
ViewSizeX
number
ViewSizeX represents the width of the game window in pixels
Code Samples
ViewSizeY
number
ViewSizeY represents the height of the game window in pixels
Code Samples
X
number
The horizontal position of the cursor on the screen.
Code Samples
Y
number
The vertical position of the cursor on the screen.
Code Samples
Methods
Events
Button1Down
This event is triggered when the primary mouse button (Button1) is pressed down. It is commonly used to detect when the player initiates a click action in the game. Developers can connect custom logic to this event for various gameplay mechanics, such as interacting with objects, selecting items, or performing attacks.
Parameters
Code Samples
Button1Up
Button1Up represents the event triggered when the primary mouse button (Button1) is released. It is typically used to detect when a player finishes a click action in the game. This event can be utilized for gameplay interactions like ending a drag-and-drop sequence, confirming selections, or stopping an ongoing action triggered by a mouse press.
Parameters
Code Samples
Button2Down
This event is triggered when the secondary mouse button (Button2) is pressed down. It is generally used to detect right-click actions in the game and is commonly utilized for mechanics such as opening context menus, rotating objects, or providing additional interaction options.
Parameters
Code Samples
Button2Up
Button2Up represents the event triggered when the secondary mouse button (Button2) is released. It is commonly used to detect when a player finishes a right-click interaction in the game. This event can be utilized for various gameplay scenarios, such as finalizing a context menu, stopping a rotation action, or ending any secondary mouse-triggered tasks.
Parameters
Code Samples
TouchStarted
TouchStarted Event Description This event is triggered when a touch input begins, such as when the player places a finger on a touch-enabled device. It can be used to implement touch-based interactions, such as tapping on objects or starting a drag action.
Parameters
Code Samples
TouchEnded
The TouchEnded event is triggered when a touch input ends, such as when the player lifts their finger off a touch-enabled device. This event is particularly useful for handling the end of touch interactions, such as releasing a button, dropping an object, or confirming a selection in touch-based gameplay mechanics.