Mouse
Mouse : Instance
Overview
Mouse provides functions related to detecting mouse button clicks
However, for stable handling of inputs in mobile environments, it is recommended to use UserInputService and ContextActionService instead of Mouse.
Properties
Hit
CFrame
Returns the CFrame value in 3D space at which the mouse pointer is pointing.
Code Samples
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local function UpdateEvent(deltaTime)
print("Hit Position : ", Mouse.Hit.Position)
end
RunService.Heartbeat:Connect(UpdateEvent)Origin
CFrame
A CFrame that represents from which direction the mouse pointer was input in 3D space.
The current location of camera becomes the starting point, and the direction of the spatial coordinates of the mouse pointer is facing is rotated to represent this value.
Code Samples
Target
BasePart
This property returns the 3D object the mouse pointer is currently pointing at.
If pointing at a non-BasePart area (e.g., sky), the Target value returns nil.
Code Samples
ViewSizeX
number
Returns the horizontal screen resolution in pixels.
Code Samples
ViewSizeY
number
Returns the vertical screen resolution in pixels.
Code Samples
X
number
Returns the horizontal coordinate on screen in pixels when the mouse is clicked.
Code Samples
Y
number
Returns the vertical coordinate on screen in pixels when the mouse is clicked.
Code Samples
Methods
Events
Button1Down
This event is executed when the player presses the left mouse button.
Parameters
Code Samples
Button1Up
This event is executed when the player releases the left mouse button.
Parameters
Code Samples
Button2Down
This event is executed when the player presses the right mouse button.
Parameters
Code Samples
Button2Up
This event is executed when the player releases the right mouse button.
Parameters
Code Samples
TouchEnded
(deprecated) This event is executed when the player releases their finger from the screen.
It is recommended to use the TouchEnded event of UserInputService.
Parameters
number x
number y
number z
Code Samples
TouchStarted
(deprecated) This event is executed when the player presses the screen.
It is recommended to use the TouchStarted event of UserInputService.
Parameters
number x
number y
number z
Code Samples
See also
Mobile Input HandlingLast updated