Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i detect a player jump with a script?

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?

1 answer

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

3 comments

0

it should work but one problem, the character might not always exist in time, remember we have to do character = localplayer.Character or localplayer.CharacterAdded:Wait()

0

Put in StarterGui.

0

It detects the jumps, but i added another non local variable to the local script (i placed the script in playerstarterscripts btw), and i want to do the current jumps variable + 1 each jump and make the gui text in the StarterGui that variable. But it doesnt work, also placing the script in startergui doesnt work, it doesnt work at all then.

This discussion is preserved as it was. New answers, comments, and votes are closed.