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
For information on how to obtain the mouse object, please see the
Note, developers are recommended to use
UserInputService instead of the
Mouse object in new work.
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.