Getting back into scripting after a long break and I decided to use ContextActionService over UserInputService
The player refuses to jump, literally EVERY single line of the code prints if I add a print statement, it’s just the self.humanoid:SetStateEnabled() that doesn’t want to do anything
this worked before I switched to ContextActionService, any guidance?
local keyBegan = {
[Enum.KeyCode.W] = function() table.insert(movement.activeDirections, Enum.KeyCode.W) end,
[Enum.KeyCode.A] = function() table.insert(movement.activeDirections, Enum.KeyCode.A) end,
[Enum.KeyCode.S] = function() table.insert(movement.activeDirections, Enum.KeyCode.S) end,
[Enum.KeyCode.D] = function() table.insert(movement.activeDirections, Enum.KeyCode.D) end,
[Enum.KeyCode.LeftShift] = function() movement.shiftHeld = true end,
[Enum.KeyCode.Space] = function()
if movement.climbing then
movement:Climb(false)
else
movement:Jump()
end
end
}
local function handleKey(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin and keyBegan[inputObject.KeyCode] then
keyBegan[inputObject.KeyCode]()
elseif inputState == Enum.UserInputState.End and keyEnded[inputObject.KeyCode] then
keyEnded[inputObject.KeyCode]()
end
return Enum.ContextActionResult.Pass
end
for key in pairs(keyBegan) do
ContextActionService:BindAction(key.Name, handleKey, false, key)
end
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
movement:UpdateRunningState()
end)
jump function if relevant:
function movement:Jump()
local state = self.humanoid:GetState()
if (state == Enum.HumanoidStateType.Landed or state == Enum.HumanoidStateType.Running) then self.canClimb = true
elseif state == Enum.HumanoidStateType.Freefall then return end
if self.canJump then
self.canJump = false
self.humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
task.wait(.45)
self.canJump = true
else
self.humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
end