Is there a more optimal way to check if a player has jumped (when they have landed)

I’ve been making this script(specifically for a diving board) that when you land after jumping, it fires an event. It works relatively ok most of the time but it has one major flaw with it: You can walk off an edge and it considers it as if it has jumped. I was wondering if there was a better way to detect whether they actually jumped or not. Other information : The game also uses the classic jump delay script, so I can’t have it check for spacebar input to judge whether they actually jumped Here is the code I currently use.


local hasJumped = false
local h=script.Parent:WaitForChild("Humanoid")
h.Changed:connect(function(prop)
		if prop and prop== "Jump" and humanoid.Jump == true and hasJumped ~= "A" then
		print("cool")
		hasJumped = true
	elseif humanoid:GetState() == Enum.HumanoidStateType.Landed and hasJumped == true then
		print("FELL")
		hasJumped = "A"
		game.ReplicatedStorage.Bounce:FireServer()
		wait(.5)
		hasJumped = false
		end
end)



One of the most effective ways I know of would prob be this:

local hasJumped = false

-- jumped --

char:WaitForChild('Humanoid'):GetPropertyChangedSignal("Jump"):Connect(function()
       hasJumped = true
end)

-- landed --

char:WaitForChild('Humanoid').StateChanged:Connect(function(old, new) print(new)
	if new == Enum.HumanoidStateType.Landed then
		hasJumped = false
	end
end)

4 Likes

You have two options here, either to do as @BANSA168 rightly suggested and listening to the jump property or you coul use your current code and check the players velocity. I’d suggest the prior.

1 Like