ContextActionService Bug

I’m making a basic LocalScript using ContextActionService to bind crouch and sprint actions to C and Left Shift, respectively. When you hold Left Shift, hold C, and then let go of Left Shift, it will fire an extra “Begin” InputState from the C key, even though it’s not being pressed again.

Here’s my output showing the extra “Begin” InputState (line 4):
image

Here’s a stripped-down script that will repeatedly cause this error:

local contextActionService = game:GetService("ContextActionService")

local function crouch (actionName, inputState, inputObject)
	print("Crouch "..tostring(inputState))
end

local function sprint (actionName, inputState, inputObject)
	print("Sprint "..tostring(inputState))
end

contextActionService:BindAction("Crouch", crouch, false, Enum.KeyCode.C)
contextActionService:BindAction("Sprint", sprint, false, Enum.KeyCode.LeftShift)

I would surely appreciate any information on why this is happening. Thanks in advance.

1 Like

I’m not exactly sure why this happens, but :BindActionAtPriority deals with issues with overlapping key inputs. It allows you to set the priority of an input as the 4th argument.
Here’s the same code you provided but using the different method:

local contextActionService = game:GetService("ContextActionService")

local function crouch (actionName, inputState, inputObject)
	print("Crouch "..tostring(inputState))
end

local function sprint (actionName, inputState, inputObject)
	print("Sprint "..tostring(inputState))
end

contextActionService:BindActionAtPriority("Crouch", crouch, false, 2, Enum.KeyCode.C)
contextActionService:BindActionAtPriority("Sprint", sprint, false, 1, Enum.KeyCode.LeftShift)

image

1 Like

Thanks for the reply. That is an interesting solution idea; however, it still is having the same issue. I tried reversing the priority to see if that would help, but the error persists.
The output you provided shows crouch - sprint - sprint - crouch, but the sequence that causes the bug starts with sprint and then crouch. I appreciate your looking into it though!