ClickDetectors and CAS:BindActivate()

ClickDetectors weren’t working in my game with a controller, despite the DevHub saying that it should fire with RightTrigger.

For gamepad input, the right trigger button will fire the MouseClick event and center dot will trigger MouseHoverEnter/MouseHoverLeave.

Source: ClickDetector | Documentation - Roblox Creator Hub


After excruciating testing, I finally realized that having a custom ControlScript (LocalScript in StarterPlayerScripts named “ControlScript” removes the default player controller) was the issue.

Apparently, what the Hub claims is “default behavior” is actually set by the ControlScript, and you need to handle it yourself otherwise.

Once I knew it was something in the ControlScript, I had to pore over the default one to find what it did to handle ClickDetectors.

Turns out, you have to set ContextActionService:BindActivate() to Enum.KeyCode.ButtonR2 in order to get the expected behavior.

However, the documentation page for CAS:BindActivate() is faulty, so that wasn’t easy to figure out. it never mentions that it affects ClickDetectors.

Bind an KeyCode that can be used with an UserInputType to activate a Tool (or a HopperBin). When the respective key is pressed, it will fire the Mouse.Button1Down event on the mouse sent to Tool.Equipped (or HopperBin.Selected). This in turn fires the Tool.Activated event if Tool.ManualActivationOnly is not set to true.

Source: ContextActionService | Documentation - Roblox Creator Hub


Update the ClickDetector page to say that it fires from the defined CAS:BindActivate(), and that the default ControlScript sets it to RightTrigger by default.

Update the BindActivate page to say that it fires the MouseClick on ClickDetectors as well.

9 Likes

Thank you for doing some research into this; I’ll admit when I originally wrote the ClickDetector page I wasn’t aware that CAS’ BindActivate was a factor. Clearly there’s a hole to be filled on these pages, so I’ll make sure they’re taken care of. Will update this thread once that’s done.

2 Likes

I think very few people were aware of that behavior (and took me quite a while to reverse engineer it), which is why it’s important we document it.
Thank you so much for being on top of this, your work is truly important to the success of the platform.

3 Likes

I’ve updated these pages:

Hopefully this will be more clear!

3 Likes

Please update this page the explanation is EXTREMELY vague and there is no sample code at all.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.