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

Button2Down

The Button2Down even fires when the the player presses their right mouse button.

This can also be accessed from a Tool. For example, when placed in a LocalScript, the code below prints Button2Down whenever the right mouse button is pressed:

local Tool = script.Parent --make sure this is a Tool object

Tool.Equipped:Connect(function(Mouse)
	Mouse.Button2Down:Connect(function()
		print("Button2Down")
	end)
end).

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.

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

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


Code Samples


Color Randomizer Tool

The following code sample, when placed in StarterPlayerScripts will create a tool in the player’s backpack that, once equipped, will change the BasePart/BrickColor of every BasePart the player clicks on.