ContextActionService:GetButton() always returns nil after binding 7 actions

After binding 7 actions with ContextActionService, the GetButton() function will always return a nil value.

The handler function appears to work fine and a button will appear on the screen, however, the function returns nil.

I have only tested this bug in studio, and only started noticing it today.

For a test file, check the local script named “Test” included in the download.

Download: ContextActionBug.rbxl (22.3 KB)

Test Code
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

Prints Failed at iteration 8

6 Likes

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

3 Likes

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.

2 Likes

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

6 Likes

Thanks for the report CaptinLetus,
We will investigate this issue.

3 Likes

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.

11 Likes

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.

1 Like

Its been a year and its still happening, any updates?

3 Likes

I am also wondering this as it is getting in the way of pushing out an update for my game now :sob:

1 Like

You can create a custom CAS wrapper to get around it

I just made a module that keeps track of all my buttons (renames a button as soon as it creates it and keeps it in an array)

1 Like

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-

3 Likes

It’s been two years and it’s still hapening, any updates?

4 Likes

I’ve had to resort to using my own implementation :person_shrugging:

Might make it public if enough people want it

Functions basically the same, but is just easier to use overall

1 Like

cant seem to get around this unless i make my own buttons which will take, time so do you mind sharing please?

1 Like

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

1 Like

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.

1 Like

Its been 3 years and its still happening, any updates?

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.

1 Like

This ticket has been “Closed”:

i.e., No one is tracking it. It might have been done accidentally, and it might need to be re-reported.