PcoWSkbVqDnWTu_dm2ix
The Developer Hub is now deprecated and information on this page may no longer be accurate. To see our new and improved documentation, please click here. You can read more about the future of documentation here.
Collapse Sidebar

Move

Fired when the mouse is moved.

Note, this event is fired when the mouse’s position is updated, therefore it will fire repeatedly whilst being moved.

For information on how to obtain the Mouse object, please see the Mouse page.

Developers can find out the position of the mouse in world-space, and if it is pointing at any BasePart using the Mouse/Hit and Mouse/Target properties.

mouse.Move:Connect(function()
	local position = mouse.Hit.p
	local target = mouse.Target
	print(target, position)
end)

Note, developers are recommended to use UserInputService instead of the Mouse object in new work.


Code Samples


Move Parts with the Mouse

The example below allows the Players/LocalPlayer|local player to move parts with their mouse.

When the player presses their left mouse button over a part, that part is the Mouse/Target|mouse's target and becomes the point. Until the player releases their left mouse button, that part will move to the mouse’s world position when the player moves their mouse.

Note that the Mouse/TargetFilter property allows the code to ignore the part being moved when determining the mouse’s world position.

The code should work as expected when placed in a LocalScript.