The module is designed to replace ClickDetectors in a way that closely resembles them, while also adding missing events and fixing issues that have always been bugging me.
Example usage
local click_detector = require(ClickDetector2).new(parent)
-- direct replacement of Instance.new("ClickDetector", parent)
click_detector.MaxActivationDistance = 16
click_detector.MouseButton1Click:Connect(function(player, hit)
...
end)
Events
MouseEnter
-
MouseLeave
MouseButton1Up
MouseButton1Down
MouseButton1Click
-
MouseButton1Release
While the first three events are fairly self-explanatory and match their equivalents used in GuiButtons, this one probably isn’t. This event will only fire afterMouseButton1Down
has been triggered and the player releases the same mouse button, not necessarily while hovering over the part.
… analogously for MouseButton2
and MouseButton3
Properties
MouseIcon: string
MaxActivationDistance: number
-
Enabled: boolean
This property doesn’t exist in actual ClickDetectors, but I thought it could be more elegant than setting theMaxActivationDistance
to0
. You can still do that though.
Differences
- ClickDetectors2 are linked to
RenderStepped
, allowing their positions to update every render cycle. This ensures that the module works seamlessly on parts in a moving object (e.g., a vehicle), no matter how small the part is. - The server verifies the actual distance between the player’s character and the part (yes, this is not the case in ClickDetectors).
- The events have different names (matching those of GuiButtons), but I believe it’s not too difficult to figure out their replacements.
- You can’t add the ClickDetector2 to a model. Sorry!
- You can’t have more than one ClickDetector2 in a part.
Download
ClickDetector2.rbxm (8.6 KB)