local ContextActionService = game:GetService("ContextActionService")
local function h() end
for i = 1, 10 do
ContextActionService:BindAction(tostring(i), h, true)
local button = ContextActionService:GetButton(tostring(i))
if not button then
warn("Failed at iteration", i)
break
end
end
I’ve resorted to just writing my own replacement for the ContextActionService. I will continue using this replacement until the problem is addressed.
New developers/inexperienced scripters won’t have the luxury of writing their own replacements though. My solution should not be seen as the final solution to this bug
This is a bit of a pain - I’ve heard whispers of this in development spheres where people have to set up their own Interfaces for it (which while not difficult shouldn’t be necessary).
Hopefully this report gets more attention, until then you could maybe open source your work around for other users.
You can just hook up the action you feed to ContextActionService to mouse click events of a regular Text/ImageButton, it’s not really rocket science.
The :GetButton() API is really quirky because you likely need to dress up / reposition the button you get back anyway, so I’m not sure if there’s much benefit over simply connecting the resulting action to some UI button yourself. That also allows you to attach the action to prefab buttons in your UI.
The benefit is making input detection simpler. ContextActionService allows us to bind input from multiple devices seamlessly. Having to create a whole separate system for touch displays defeats the purpose of having touch support within the ContextActionService
Update:
As you noticed, the code currently has an invisible hard limit of 7 creatable buttons for the ContextActionService. This seems completely arbitrary, and we can certainly uncap it. I will create a ticket to do so.
Sure, though in my experience :GetButton() sort of binds you down in terms of how you set up your UI. Ideally it should allow you to pass an existing instance, that way you don’t need to mangle your prefabs / hack it into a declarative way of writing UI (Roact) or otherwise have special code to replace an existing UI instance. It is not very difficult to bind input from multiple devices without using :GetButton().
Looks like your problem will be solved by above, but food for thought.
It’s still happening for me. I was so confused on why my buttons randomly returned nil when they are coded properly. It’s been 2 years since this post and it’s still not fixed, what’s the point of using CAS if it doesn’t work correctly on touched devices-
CAS:GetButton() is giving me a lot of headaches right now. Whether its returning nil when it shouldnt, or possibly yielding when it shouldnt, its making it very frustrating to work with where i need to come up with workarounds to get this api to working. Hoping to see a resolution to this soon
I’m not sure why Roblox won’t allow binding of more than seven items with their ContextActionService, but this is a known limitation. I have released a replacement in Community Resources that resolves this. In addition to being mostly compatible with Roblox’s version, it also has a number of additions and is Parallel LUA compliant.
It’s funny how every time i find an arbitrary nonsense issue in the Roblox Engine there is always a 4+ year old forum post mentioning it where a Roblox Staff says “We have filed an internal ticket” and nothing changes.