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

GetMouseLocation

The GetMouseLocation function returns a DataType/Vector2 of the current screen location of the player’s Mouse in pixels.

Note: If the location of the mouse pointer is offscreen or the players device does not have a mouse, such as a gamepad or touchscreen, the value returned will be undetermined.

Since UserInputService only runs client-side, this function will only work when used in a LocalScript.

Returns

Return Type Summary

The current screen location of the mouse.


Code Samples


UserInputService:GetMouseLocation

GetMouseLocation returns a Vector2 of the current screen location of the player’s mouse pointer in pixels. If the location of the mouse pointer is offscreen or the player’s device does not have a mouse the value returned will be undetermined.

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
 
-- Arbitrary wait to give user time to position mouse
wait(2) 
 
local mouseLocation = UserInputService:GetMouseLocation()
print("The mouse location is", mouseLocation)