I’m making a script that controls jumping, because I want to precisely control when players can and cannot jump. I’m using ContextActionService to bind the CharacterJump PlayerAction to a function called “jump”, at priority 1000 which should be lower (i.e. prioritized higher) than the default jump action, which is at 2000.
This should result in the “jump” function being called every time the player sends input to make them jump, e.g. pressing the space bar. However, sometimes this just does nothing. In studio it occasionally works, and I have no idea what causes it to do so. When testing in-game, it never works.
Here is the relevant part of the script:
function jump(_, inputState)
print("jumping", inputState)
if inputState == Enum.UserInputState.Begin then
--more jumping related logic
end
end
function initialize()
spawn(function()
local playerScripts = player:WaitForChild("PlayerScripts")
local controlScript = playerScripts:WaitForChild("PlayerModule")
ActionService:BindActionAtPriority("jumpAction", jump, false, 1000, Enum.PlayerActions.CharacterJump)
print("bound")
end)
RunService.RenderStepped:Connect(function()
--some logic checking if the player should be able to jump
end)
end
initialize()
I put in the print("bound")
statement to verify that the game actually reaches that point in the script. This always prints, even if nothing works and the binding doesn’t show up in the developer / F9 console. When binding doesn’t work, the print statement inside jump()
runs, printing jumping Enum.UserInputState.Cancel
to the console.
I can’t continue working on my game as long as this keeps happening, and I have no idea what might be causing it. I tried binding to KeyCode.Spacebar instead if CharacterJump, as well as using BindAction instead of BindActionAtPriority. I even tried binding at priority 3000, in case I got the way that works wrong. None of those made any difference. I also tried putting the jumping script in another place entirely, to verify that it’s not another script messing stuff up. The exact same happens in the new place.
You can try it out for yourself at Boat Game - Roblox
I really hope someone can help me, it’s been bugging me for a while now and I’m at my wits’ end here