PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

ClickDetector

Show deprecated

ClickDetector

Show deprecated

ClickDetector allows Script|Scripts and LocalScript|LocalScripts to receive pointer input on 3D objects. They are placed inside BasePart|BaseParts, Model|Models and Folder|Folders. They can detect basic mouse events: enter, leave, left click and right click. Touch input on UserInputService/TouchEnabled|TouchEnabled devices will also fire click events. For gamepad input, the right trigger button will fire the ClickDetector/MouseClick|MouseClick event and center dot will trigger ClickDetector/MouseHoverEnter|MouseHoverEnter/ClickDetector/MouseHoverLeave|MouseHoverLeave.

Below is a simple template script for working with ClickDetectors. Paste it into a Script or a LocalScript.

local clickDetector = workspace.Part.ClickDetector

function onMouseClick()
	print("You clicked me!")
end

clickDetector.MouseClick:connect(onMouseClick)

ClickDetector/MaxActivationDistance|MaxActivationDistance can be used to limit the distance a player may be from a ClickDetector object before it is no longer clickable.

ClickDetector events fire on both the client and the server, even when Workspace/FilteringEnabled|FilteringEnabled is on. Since LocalScripts|LocalScript will only run if they are descendants of a Player or Player’s 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 would detect a user input, only the deepest ClickDetector will fire events. If an action bound with ContextActionService uses the same input as a ClickDetector, the action bound with ContextActionService will take priority over ClickDetector events. If two ClickDetectors are siblings, the first ClickDetector will take priority. UserInputService/InputBegan will fire before ClickDetector events. Due to the nature of user input, you ought not depend on all ClickDetector/MouseHoverEnter|MouseHoverEnter events to fire a matching ClickDetector/MouseHoverLeave|MouseHoverLeave event.

Properties

Content

CursorIcon

Sets the mouse icon that will be displayed when the mouse is hovered over this ClickDetector

float

MaxActivationDistance

Maximum distance between a character and the ClickDetector for the character to be able to click it

Functions

Events

RBXScriptSignal

MouseClick ( Instance playerWhoClicked )

Fires when a player left clicks on the ClickDetector

RBXScriptSignal

MouseHoverEnter ( Instance playerWhoHovered )

Fired when the ClickDetector's parent is hovered upon by a player

RBXScriptSignal

MouseHoverLeave ( Instance playerWhoHovered )

Fired when a player’s mouse moves off of the ClickDetector's parent

RBXScriptSignal

RightMouseClick ( Instance playerWhoClicked )

Fires when a player right clicks on the ClickDetector