How to Detect when the player jumps?

What I am currently trying to achieve is that when the player jumps the desired value should be added to the leaderstats. But I am not sure how do I detect when the player jumps.

I’ve gone through some posts in the developer hub but still ain’t sure and confused.

https://devforum.roblox.com/t/how-detect-a-jump-when-in-platformstand/102979

https://devforum.roblox.com/t/how-to-detect-when-humanoid-jumps/34852

https://devforum.roblox.com/t/does-any-of-you-guys-know-of-a-reliable-way-to-detect-when-a-player-jumps/282638

I’d love if someone could explain to me in a bit detailed way as I am not much experienced with scripting.

9 Likes

There’s the UserInputService JumpRequest event which will fire when the player requests to jump.

You can use this in a LocalScript and :FireServer a RemoteEvent to handle it on the server.
Remember to include a debounce for each player to combat exploiters.

15 Likes

There are many possible ways I can think of:

UserInputService.JumpRequest

This event fires when the player wants to jump. The thing is has to be handled on the client, so a RemoteEvent will have to be used to change the data, but you should make it not exploitable, which means that a cooldown should be implemented

While Loop and Humanoid.Jump

I’m not so sure on this one, but you basically use a while Loop and constantly check if the player’s humanoid has the jump property set to true, which signifies that the player has jumped

4 Likes

Use UserInputService.JumpRequest if you need to know when the player attempts to jump, Humanoid.Jumping if you need to see when the Humanoid successfully jumps or Humanoid.StateChanged if you’re working with multiple HumanoidStateTypes, including jumping.

Don’t use JumpRequest if you’re trying to detect when the player jumps. Use it only when you need to check if the player is attempting to jump. As well (cc @Raretendoblox), don’t use a loop here. It is largely unnecessary as events are provided in the API to check when jumps occur.

14 Likes

You can use an event here

humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
    print(humanoid.Jump)
end)
24 Likes

Thanks for helping out everyone!

4 Likes

YAY!!! finally… something that actually works :') i just wanted to decrease stamina on jump and this is perfect. (I’m running a remote event on the jump while turning value (local inside script) true, if value is true and lands the value == false, and finally UIS.JumpRequest is working perfectly.

3 Likes