PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

GetMouse

The GetMouse Player function returns the Mouse being used by the client. The player’s mouse instance can be used to track user mouse input including left and right mouse button clicks and movement and location.

The UserInputService service provides additional functions and events to track user input - especially for devices that do not use a mouse.

##Notes

  • This item must be used in a LocalScript to work as expected online.
  • Following an update in July 2014, the mouse’s icon can now be set with this method.

Returns

Return Type Summary

An instance of the player’s mouse.


Code Samples


How to Track Mouse Input

The below example will print:

Button 1 is down

whenever the Players/LocalPlayer left clicks.

local Player = Game.Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.Button1Down:Connect(function()
     print("Button 1 is down")
end)