Roblox Api Mouse
Local position vector2newmousex mousey.
Roblox api mouse. This property can be used in conjunction with mousey to produce a datatypevector2 representing the mouses position. It can be accessed through playergetmouse called on the playerslocalplayer in a localscript. The mouse is locked and cannot move from its current position on the users screen at the time of locking. It is most notable for the mouseiconicon property which changes the cursors appearance.
Developers can find out the position of the mouse in world space and if it is pointing at any basepart using the mousehit and mousetarget properties. For the example to work expected the localscript containing the code should be a child of the gui button. The mouse moves freely around the users screen. The code below visualizes the difference between mousehit and mouseoriginin order to do this the code uses the datatypevector3 positions of the hit and origin datatypecframe values using p.
The difference is that the origin is where the mouse came from its origin and the hit is the position where the mouse hits is when the. The position is measured in pixels relative to the top left corner under the topbar. The x property describes the horizontal component of the mouses position on the screen. The code sample below demonstrates how to use the guibuttonmousebutton1click and guibuttonmousebutton2click events to handle user left and right mouse button input on a guibutton.
Note developers are recommended to use userinputservice instead of the mouse object in new work. Mouse origin vs mouse hit vs currentcamera position. It is also passed by the toolequipped event. For information on how to obtain the mouse object please see the mouse page.