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.
