The ClickDetector class is used to make an object able to be selected, and if applied, perform an action. To apply it, select a brick, then go to Insert > Object > ClickDetector. If you apply a script to purchase an object by clicking, then when you hover over the object, your cursor will turn to a hand, and if you click, the script will be executed. You can also use this technique on doors, e.g. placing a ClickDetector brick that when selected sets an object CanCollide setting to false, allowing passage. Good for making doors and such. It was released on April 2, 2008, alongside email verification and Sparkles.[1] At an unknown date, the ClickDetector pointer was revamped.
Usage[]
When a player clicks a ClickDetector's parent brick, this event will fire including the player who clicked.
Example:
script.Parent.MouseClick:connect(function(player)
print(player .. " has clicked the part!")
end)
Properties
CursorIcon: ContentId
Sets the image of the cursor when this ClickDetector is hovered.
- Category: Image.
- Serialization: can save and load.
- Thread safety: read safe
CursorIconContent: Content
- Category: Image.
- Serialization: can save and load.
- Thread safety: read safe
MaxActivationDistance: float
The maximum distance a Player's character can be from the ClickDetector's parent Part that will allow the Player's mouse to fire events on this object.
- Category: Data.
- Serialization: can save and load.
- Thread safety: read safe
Events
MouseClick(playerWhoClicked: Player)
| Name | Type | Description |
|---|---|---|
| playerWhoClicked | Player | The Player that clicked on the detector. |
This event is fired when the ClickDetector is clicked on. The player who clicked on the ClickDetector is given as the playerWhoClicked variable.
- Thread safety: unsafe
MouseHoverEnter(playerWhoHovered: Player)
| Name | Type |
|---|---|
| playerWhoHovered | Player |
- Thread safety: unsafe
MouseHoverLeave(playerWhoHovered: Player)
| Name | Type |
|---|---|
| playerWhoHovered | Player |
- Thread safety: unsafe
RightMouseClick(playerWhoClicked: Player)
| Name | Type |
|---|---|
| playerWhoClicked | Player |
- Thread safety: unsafe
mouseClick(playerWhoClicked: Player)
| Name | Type |
|---|---|
| playerWhoClicked | Player |
Use MouseClick instead.
- Thread safety: unsafe
External links[]
- ↑ Shedletsky, John (2008, April 2). "Verified Sparkle Places – Fantastic Release". From Roblox Blog. Archived from the original on October 20, 2019.