Context Action Service yielding... weird results

I’m currentley using CAS to bind and unbind the jump key to certain functions, so it is mobile accessible.

However, I am running into an error with the unbinding and rebinding of the jump button, where it will only work before the tool is equipped, then once it is unequipped it stops working.

Here is the code in question;

local function OnJumpAction(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin and not equipped.Value then
		humanoid.JumpPower = 50
		if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
			print("a")
		end
	end
end

equipped.Changed:Connect(function()
	if equipped.Value == true then
		humanoid.JumpPower = 0
		ContextActionService:BindAction("flickerStep", OnFlashStepAction, true, Enum.KeyCode.Space)
	elseif equipped.Value == false then
		ContextActionService:BindAction("jumpAction", OnJumpAction, false, Enum.KeyCode.Space)
	end
end)

humanoid.JumpPower = 50

I have tried many different ideas, yet none have worked

1 Like

Instead of using equipped.Changed you should use Tool.Equipped and Tool.Unequipped

I can change it to that, but that won’t fix the issue. The tool.equipped and unequipped are set to the equippedvar on the server either way

Whats the aim? Are you supposed to be able to jump when the tool is equipped?

1 Like

No, when the tool is unequipped you are supposed to be able to jump, but when it is equipped the jump action should be replaced by the flashstep

when you bind spacebar to OnFlashStepAction, it also unbinds the jump key i think, once you unbind spacebar to OnFlashStepAction, you should be able to jump again, so it should look something like this maybe?

equipped.Changed:Connect(function()
	if equipped.Value == true then
		ContextActionService:BindAction("flickerStep", OnFlashStepAction, true, Enum.KeyCode.Space)
	elseif equipped.Value == false then
		ContextActionService:UnbindAction("flickerStep" )
	end
end)