ClickDetector
Memory category | Instances |
---|
Member index 8
Description
ClickDetector allows Scripts and LocalScripts to receive pointer input on 3D objects through their MouseClick event. They work when parented to BasePart, Model, or Folder objects. They detect basic mouse events: enter, leave, left click and right click. Touch input on TouchEnabled devices also fires click events.
The default control scripts bind ButtonR2 to interact with ClickDetectors using ContextActionService:BindActivate(), which can also be used to override this. When using gamepads, the center dot triggers MouseHoverEnter and MouseHoverLeave. The bound activation button fires MouseClick.
MaxActivationDistance can be used to limit the distance a player may be from a click detector before it is no longer clickable.
ClickDetector events fire on both the client and the server. Since a LocalScript will only run if it descends from a Player or player Character, it's usually not useful to put a LocalScript inside a ClickDetector, since the script won't run or the object won't be clickable. If you need a LocalScript to detect ClickDetector events, StarterPlayerScripts may be a better place instead.
Input Priority
If multiple ClickDetectors may detect user input, only the deepest will fire events. If two ClickDetectors are siblings, the first will take priority.
If an action bound with ContextActionService uses the same input as a ClickDetector, the action bound with ContextActionService will take priority over the click detector's events.
UserInputService.InputBegan will fire before ClickDetector events.
History 30
- 645 Change ValueType of CursorIcon from Content to ContentId
- 553 Change PreferredDescriptor of mouseClick from to MouseClick
- 553 Add
- 553 Change Default of MaxActivationDistance from to 32
- 486 Change ThreadSafety of MaxActivationDistance from ReadOnly to ReadSafe
- 486 Change ThreadSafety of CursorIcon from ReadOnly to ReadSafe
- 483 Change Parameters of mouseClick from (playerWhoClicked: Instance) to (playerWhoClicked: Player)
- 483 Change Parameters of RightMouseClick from (playerWhoClicked: Instance) to (playerWhoClicked: Player)
- 483 Change Parameters of MouseHoverLeave from (playerWhoHovered: Instance) to (playerWhoHovered: Player)
- 483 Change Parameters of MouseHoverEnter from (playerWhoHovered: Instance) to (playerWhoHovered: Player)
- 483 Change Parameters of MouseClick from (playerWhoClicked: Instance) to (playerWhoClicked: Player)
- 462 Change ThreadSafety of mouseClick from to Unsafe
- 462 Change ThreadSafety of RightMouseClick from to Unsafe
- 462 Change ThreadSafety of MouseHoverLeave from to Unsafe
- 462 Change ThreadSafety of MouseHoverEnter from to Unsafe
- 462 Change ThreadSafety of MouseClick from to Unsafe
- 462 Change ThreadSafety of MaxActivationDistance from to ReadOnly
- 462 Change ThreadSafety of CursorIcon from to ReadOnly
- 301 Add CursorIcon
- 292 Change Tags of mouseClick from [] to [Deprecated]
- 282 Add RightMouseClick
- 281 Remove RightMouseClick
- 282 Add RightMouseClick
- 254 Change Tags of mouseClick from [Deprecated] to []
- 68 Add mouseClick
- 47 Add MouseHoverLeave
- 47 Add MouseHoverEnter
- 47 Add MouseClick
- 47 Add MaxActivationDistance
- 47 Add ClickDetector
Members 8
CursorIcon
Type | Default | |
---|---|---|
ContentId |
Sets the cursor icon to display when the mouse is hovered over the parent of this ClickDetector or DragDetector. If this property is left blank, the detector will use the default icon.
To change the cursor icon, set this property to the asset ID of the image you'd like to use.
Thread safety | ReadSafe |
---|---|
Category | Image |
Loaded/Saved | true |
History 4
- 645 Change ValueType of CursorIcon from Content to ContentId
- 486 Change ThreadSafety of CursorIcon from ReadOnly to ReadSafe
- 462 Change ThreadSafety of CursorIcon from to ReadOnly
- 301 Add CursorIcon
MaxActivationDistance
Type | Default | |
---|---|---|
float | 32 |
This property controls the maximum distance, in studs, between a Character and the ClickDetector or DragDetector for the player to be able to interact with it. For instance, a character within 10 studs of a ClickDetector or DragDetector with a max activation distance of 5 would not be able to use the detector because they are out of range.
Thread safety | ReadSafe |
---|---|
Category | Data |
Loaded/Saved | true |
History 4
- 553 Change Default of MaxActivationDistance from to 32
- 486 Change ThreadSafety of MaxActivationDistance from ReadOnly to ReadSafe
- 462 Change ThreadSafety of MaxActivationDistance from to ReadOnly
- 47 Add MaxActivationDistance
MouseClick
Parameters (1) | |
---|---|
playerWhoClicked | Player |
This event fires from either a Script or LocalScript when a player interacts with a ClickDetector or DragDetector via the following inputs:
- On platforms with a mouse, when the player left mouse clicks.
- On TouchEnabled platforms, when the player taps.
- On GamepadEnabled platforms, when the center dot is over the same model and the A button is pressed and released.
Note that the player's Character must be within the MaxActivationDistance of the detector.
Thread safety | Unsafe |
---|
History 3
- 483 Change Parameters of MouseClick from (playerWhoClicked: Instance) to (playerWhoClicked: Player)
- 462 Change ThreadSafety of MouseClick from to Unsafe
- 47 Add MouseClick
MouseHoverEnter
Parameters (1) | |
---|---|
playerWhoHovered | Player |
This event fires from either a Script or LocalScript when the parent of a ClickDetector or DragDetector is hovered over by a player. This does not entail explicit interaction with the detector, for which you can listen to either MouseClick and RightMouseClick events.
Due to the nature of user input, you should not depend on all MouseHoverEnter events firing a corresponding MouseHoverLeave event.
Thread safety | Unsafe |
---|
History 3
- 483 Change Parameters of MouseHoverEnter from (playerWhoHovered: Instance) to (playerWhoHovered: Player)
- 462 Change ThreadSafety of MouseHoverEnter from to Unsafe
- 47 Add MouseHoverEnter
MouseHoverLeave
Parameters (1) | |
---|---|
playerWhoHovered | Player |
This event fires from either a Script or LocalScript when a player's cursor hovers off the parent of a ClickDetector or DragDetector. This does not entail explicit interaction with the detector, for which you can listen to either MouseClick and RightMouseClick events.
Due to the nature of user input, you should not depend on all MouseHoverLeave events firing after a corresponding MouseHoverEnter event.
Thread safety | Unsafe |
---|
History 3
- 483 Change Parameters of MouseHoverLeave from (playerWhoHovered: Instance) to (playerWhoHovered: Player)
- 462 Change ThreadSafety of MouseHoverLeave from to Unsafe
- 47 Add MouseHoverLeave
RightMouseClick
Parameters (1) | |
---|---|
playerWhoClicked | Player |
This event fires from either a Script or LocalScript when a player right clicks their mouse cursor on a ClickDetector or DragDetector. Note that the player's Character must be within the MaxActivationDistance of the detector.
Thread safety | Unsafe |
---|
History 5
- 483 Change Parameters of RightMouseClick from (playerWhoClicked: Instance) to (playerWhoClicked: Player)
- 462 Change ThreadSafety of RightMouseClick from to Unsafe
- 282 Add RightMouseClick
- 281 Remove RightMouseClick
- 282 Add RightMouseClick
mouseClick
Parameters (1) | |
---|---|
playerWhoClicked | Player |
Thread safety | Unsafe |
---|
History 6
- 553 Change PreferredDescriptor of mouseClick from to MouseClick
- 483 Change Parameters of mouseClick from (playerWhoClicked: Instance) to (playerWhoClicked: Player)
- 462 Change ThreadSafety of mouseClick from to Unsafe
- 292 Change Tags of mouseClick from [] to [Deprecated]
- 254 Change Tags of mouseClick from [Deprecated] to []
- 68 Add mouseClick