Double jump for mobile and desktop

  1. I want that when the player press the space button, or jump button in case of mobile users it double jump

  2. This is just a part of the complete script

local function onInputBegan(input, gameProcessedEvent)
    if gameProcessedEvent or not (input.UserInputType == Enum.UserInputType.Keyboard or input.UserInputType == Enum.UserInputType.Touch) then
        return
    end

    if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Space or
       input.UserInputType == Enum.UserInputType.Touch and input.KeyCode == Enum.KeyCode.ButtonA then
        local now = tick()
        if now - lastJumpTime < 0.75 and stamina >= 20 then -- double jump
            Character:FindFirstChildOfClass("Humanoid"):ChangeState(Enum.HumanoidStateType.Jumping)
            doubleJumpTrack:Play()
            stamina = stamina - 15
            updateStaminaBar()
        end
    end
end

  1. Is supposed to work for desktop and mobile, but only works for desktop users.

Thanks for reading :smile:

1 Like

I think that input.KeyCode == Enum.KeyCode.ButtonA is checking for the gamepad button A and its not the Touch button on screen a mobile user has, isnt?

To use UserInputService you should use UserInputService.JumpRequest:Connect() to detect when a touch user pressed the jump touch button.

Or you could try to use ContextActionService to bind a function to the touch button of the player

1 Like