Page: ContextActionService | Documentation - Roblox Creator Hub
Issue: ContextActionService:BindActionAtPriority()
doesn’t have a working example. The fundamental problem is a missing return Enum.ContextActionResult.Pass
in both called functions. There are also a name confusion and a typo present.
Solution: I suggest the code sample be rewritten to the following example with a couple of improvements:
local ContextActionService = game:GetService("ContextActionService")
local function handleThrow(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
print("Throw")
end
-- By default, context action result is 'Sink'
return Enum.ContextActionResult.Pass
end
local function handlePunch(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
print("Punch")
end
return Enum.ContextActionResult.Pass
end
-- Punch is "stacked" as second, thus bound at a higher priority.
ContextActionService:BindAction("BindActionThrow", handleThrow, false, Enum.KeyCode.E)
ContextActionService:BindAction("BindActionPunch", handlePunch, false, Enum.KeyCode.E)
-- Throw is bound at a higher priority than Punch (priority 2 > priority 1).
-- Despite the order in which the functions were bound, handleThrow is going to
-- be called before handlePunch once Q is pressed.
ContextActionService:BindActionAtPriority("BindAtPriorityThrow", handleThrow, false, 2, Enum.KeyCode.Q)
ContextActionService:BindActionAtPriority("BindAtPriorityPunch", handlePunch, false, 1, Enum.KeyCode.Q)
All the best!