ContextActionService:GetButton() Yields infinitely

Calling ContextActionService:GetButton() after ContextActionService:BindAction() with createTouchButton = true results in an infinite yield and never returns nil.

The documentation is contradictory, it states that GetButton() yields but is expected to return nil, which it never does unless BindAction is called with createTouchButton = false.

Additionally, calling :GetButton() for an action that does not exist will also result in an infinite yield, even if the action is bound later on.

The only workaround is to create a messy coroutine implementation:

EDIT: This approach does not work. GetButton() continues to yield because it is attempting to access an internal reference that is never created, even after an ActionButton is Added to ContextActionGui. Buttons created under ContextActionGui lack unique identifiers and are identical by default, which prevents implementing a reliable custom GetButton function.

local function GetButton(Type: string)
	return ContextActionService:GetButton(Type)
end

return function(Name: string)
	local Thread = coroutine.running()
	
	local Button
	local ButtonThread
	
	repeat
		task.delay(1, function()
			if coroutine.status(Thread) ~= "dead" then
				coroutine.resume(Thread)
			end
			
			if ButtonThread then
				task.cancel(ButtonThread)
			end
		end)
		
		ButtonThread = task.spawn(function()
			Button = GetButton(Name)
			
			coroutine.resume(Thread)
		end)
		
		coroutine.yield()
	until Button
end

Expected behavior

GetButton() should not yield indefinitely, it should eventually return nil.

Events such as ContextActionService.BoundActionAdded are RobloxScriptSecurity and can not be used as a workaround.

Hi I am able to repro

but I can’t

Get this to happen. Could you share a placefile? What platforms does this happen on? Touch? Windows? Thanks

You can reproduce the second part of this issue by emulating a touch device in Studio with the following code:

local ContextActionService = game:GetService("ContextActionService")

ContextActionService:BindAction("Test", print, true)
ContextActionService:GetButton("Test")

print("Resumed")

This bug appears to occur randomly, it only happened around 25% of the time for me whilst it was more frequent for a friend of mine.

To clarify, this happened whilst emulating a touch device on Studio. I have not tested everything related to this issue. However, after attempting to replicate it on the Player with an actual mobile device, it does not seem to be an issue. It may be a Play Test or Device Emulation issue.

Hi, thanks for the report, this should now be fixed! Please let me know if you observe any additional issues!