I’ve run into some unexpected behavior with ContextActionService:UnbindAction()
that may possibly be a bug, but could also be me misunderstanding something, as this is my first time using ContextActionService.
Intended behavior when run from a local Script::
-
By holding Left Shift, “Run” should be printed.
-
Holding Left Control while still holding Shift should print “UnRun”, as the Run action has been unbound and “Cancel” has presumably been passed.
-
“Crouch” should be printed.
local CAS =game:GetService("ContextActionService")
local function HandleAction(ActionName,InputState,InputObject)
print(ActionName,InputState)
if ActionName =='Run' then
if InputState ==Enum.UserInputState.Begin then
print('Run')
elseif InputState ==Enum.UserInputState.End or InputState ==Enum.UserInputState.Cancel then
print('UnRun')
end
elseif ActionName =='Crouch' then
if InputState ==Enum.UserInputState.Begin then
print('Crouch')
CAS:UnbindAction('Run')
elseif InputState ==Enum.UserInputState.End or InputState ==Enum.UserInputState.Cancel then
print('UnCrouch')
CAS:BindAction('Run',HandleAction,false,Enum.KeyCode.LeftShift)
end
end
end
CAS:BindAction('Run',HandleAction,false,Enum.KeyCode.LeftShift)
CAS:BindAction('Crouch',HandleAction,false,Enum.KeyCode.LeftControl)
Actual behavior
- Holding Shift then holding Control dose not pass “Cancel” to the Function as it seems documented it should: ContextActionService:BindAction (roblox.com)
(“Cancel is sent if some input was in-progress and another action bound over the in-progress input, or if the in-progress bound action was unbound.”)
- Releasing Shift while still holding Control prints “Crouch” again, which seems very odd and unintentional.
I’ve looked around a bit and can’t find any similar problems reported which leads me to believe I may be understanding or implementing something wrong?