Class · inherits Instance
ClickDetector
About ClickDetector
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.
Properties 3
CursorIcon
: ContentIdSets the cursor icon to display when the mouse is hovered over the parent of thisClickDetectororDragDetector.Sets the cursor icon to display when the mouse is hovered over the parent of this
ClickDetectororDragDetector. 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.
CursorIconContent
: ContentSets the cursor icon to display when the mouse is hovered over the parent of thisClickDetectororDragDetector. Only supports asset URIs.Sets the cursor icon to display when the mouse is hovered over the parent of this
ClickDetectororDragDetector. 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. Only asset URIs are supported for this property.
MaxActivationDistance
: floatMaximum distance between a character and theClickDetectororDragDetectorfor the player to be able to interact with it.This property controls the maximum distance, in studs, between a
Characterand theClickDetectororDragDetectorfor the player to be able to interact with it. For instance, a character within 10 studs of aClickDetectororDragDetectorwith a max activation distance of 5 would not be able to use the detector because they are out of range.
Events 4
MouseClick
ClickDetector.MouseClick:Connect(function(playerWhoClicked))Fires when a player interacts with the parent of aClickDetectororDragDetector.This event fires from either a
ScriptorLocalScriptwhen a player interacts with aClickDetectororDragDetectorvia the following inputs:- On platforms with a mouse, when the player left mouse clicks.
- On
TouchEnabledplatforms, when the player taps. - On
GamepadEnabledplatforms, when the center dot is over the same model and the A button is pressed and released.
Note that the player's
Charactermust be within theMaxActivationDistanceof the detector.MouseHoverEnter
ClickDetector.MouseHoverEnter:Connect(function(playerWhoHovered))Fires when the parent of aClickDetectororDragDetectoris hovered over by a player.This event fires from either a
ScriptorLocalScriptwhen the parent of aClickDetectororDragDetectoris hovered over by a player. This does not entail explicit interaction with the detector, for which you can listen to eitherMouseClickandRightMouseClickevents.Due to the nature of user input, you should not depend on all
MouseHoverEnterevents firing a correspondingMouseHoverLeaveevent.MouseHoverLeave
ClickDetector.MouseHoverLeave:Connect(function(playerWhoHovered))Fires when a player's cursor hovers off the parent of aClickDetectororDragDetector.This event fires from either a
ScriptorLocalScriptwhen a player's cursor hovers off the parent of aClickDetectororDragDetector. This does not entail explicit interaction with the detector, for which you can listen to eitherMouseClickandRightMouseClickevents.Due to the nature of user input, you should not depend on all
MouseHoverLeaveevents firing after a correspondingMouseHoverEnterevent.RightMouseClick
ClickDetector.RightMouseClick:Connect(function(playerWhoClicked))Fires when a player right clicks their mouse cursor on aClickDetectororDragDetector.This event fires from either a
ScriptorLocalScriptwhen a player right clicks their mouse cursor on aClickDetectororDragDetector. Note that the player'sCharactermust be within theMaxActivationDistanceof the detector.
ClickDetector also has every member of Instance. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.