How to use ContextActionService to replace jump action with W?

I’m making a fighting game and I want the controls to be a typical fighting game so far I used contextactionservice to Unbind the W and S keys but I’m having difficulties changing the W key to Jump and when the S key is pressed crouch animation is plays and returns back to idle.

local ContextActionService =game:GetService("ContextActionService")
local FowardMovement = Enum.PlayerActions.CharacterForward
local BackwardMovement = Enum.PlayerActions.CharacterBackward
local JumpMovement = Enum.PlayerActions.CharacterJump


local function Sink()
	return Enum.ContextActionResult.Sink
end

----Sink forward movement 
ContextActionService:BindAction("moveForwardAction", Sink,false,FowardMovement)

----Sink backward movement 
ContextActionService:BindAction("SinkmoveBackwardAction",Sink,false,BackwardMovement)

----Sink jump movement
ContextActionService:BindAction("SinkjumpAction",Sink,false,JumpMovement)

2 Likes

I don’t know if this make sense (I’m fairly new to scripting) but this is what I tried to do and it didn’t work

local ContextActionService = game:GetService("ContextActionService")

local localPlayer = game.Players.LocalPlayer

local function Jump(actionName, inputState, input)
	if inputState == Enum.UserInputState.Begin then
		local character = localPlayer.Character
		local rootPart = character.HumanoidRootPart
		local forwardVector = rootPart.CFrame.LookVector * 100
		character.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		rootPart.Applyimpulse(forwardVector)
	end
end


script.Parent.Equipped:Connect(function()
	ContextActionService:BindAactionAtPriority("Jump",Jump,true,30000, Enum.KeyCode.W)
	
end)

script.Parent.Unequiped:Connect(function()
	ContextActionService:UnbindAction("Jump")
end)
1 Like