I am writing a game where the B button on the gamepad activates a skill. When the user is in a menu, I want B to close the menu instead.
I tried using ContextActionService and Binding the actions with priorities 1 and 2. The problem is that it fires the action on both button press, and release. So when I close my shop and unbind the close action, the B button will still trigger the player’s skill ability when they release it.
ContextActionService:BindActionAtPriority("Action1", function() print("1"), false, 1, Enum.KeyCode.ButtonB)
function UnbindFunction()
ContextActionService:UnbindAction("CloseShop")
end
ContextActionService:BindActionAtPriority("CloseShop", UnbindFunction, false, 2, Enum.KeyCode.ButtonB)
-- Pressing B on a controller will print "1", despite the UnbindFunction having higher priority before cancelling itself.