ContextActionService failing to bind sometimes

--context actionservice binding for crouching (ctrl), running (shift), and shushing (space) and triggering respective remote events

local cas = game:GetService("ContextActionService")



--run (shift, hold)
function run(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		print("running")
	elseif inputState == Enum.UserInputState.End then
		print("stopped running")
	end
end


--crouch (ctrl, toggle)
function crouch(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		print("crouching")
	end
end


--shh (space)
function shh(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin then
		print("shh")
	end
end


--bindings
cas:BindAction("Run", run, false, Enum.KeyCode.LeftShift)
cas:BindAction("Crouch", crouch, false, Enum.KeyCode.LeftControl)
cas:BindAction("Shh", shh, false, Enum.KeyCode.Space)

I had a script before that tried to unbind jumpAction the second you joined the game, and it worked the majority of the time, but sometimes it didn’t. I’ve since scrapped that, but I’m now using this script to enable some other controls. The thing is, I’m assuming there may be an issue with this failing to bind sometimes as well, so I have this script here looking for edits to maybe fix this issue, if it is one.
-Does CAS sometimes fail to bind right off the bat, or is it just when unbinding actions?
-This is in a LocalScript in StarterPlayerScripts, if that means anything

Bonus Points: The spacebar bound action doesn’t automatically disable jumping like I expected it to. Why not? (I want it to override the jumping action by the way)

2 Likes