Hello everyone, I am currently working on a game with a friend, and i am trying to make a script that increases a variable with 1 each time the character jumps. The problem is i dont know how to detect a jump with a script. Ive tried it with spacebar, but you can just spam spacebar, and it wouldnt work on mobile and console. So how do i make a jump detector script?
https://developer.roblox.com/en-us/api-reference/class/Humanoid
There is a humanoid event that is called Jumping which fires when the Jumping state enables and disables, there is also a bool from the event which indicates if the player is jumping or not.
The script below only works for localscripts, it might work for serverscripts if you fix the local Player
value.
local Player = game.Players.LocalPlayer Player.CharacterAdded:Wait() local Character = Player.Character local Humanoid = Character:WaitForChild("Humanoid") Humanoid.Jumping:Connect(function(bool) if bool == true then print(Player.Name .. " is now jumping.") else print(Player.Name .. " is no longer jumping.") end end)
I have been unable to test this script so please let me know if I did something wrong so I can correct it
Thanks to Glacitron for line 2