How to accurately check when a player jumps and when a player hits the ground?

Hello, again!

This time, I want to know on how I can accurately get and print when a player jumps or when a player lands on the floor.

I have tried to do something like this with bool-values, but it is like every time you hold the jump button on your computer, the bool-values stay frozen.

I will try to explain and show about what I am talking about to the best of my ability, so prepare for your mind to be taken out of this world.

So, here is a video of me jumping:
robloxapp-20221230-2039560.wmv (3.0 MB)

On the dev console, the states that are being printed and they are pretty accurate according to the game.

Now, if I use a bool-values instead, here is what happens: [twist]
Screenshot 2022-12-30 204948

If I start to hold space to jump, the bool-value’s value for jumping becomes stuck on true, as-well as the bool-value’s value for checking when a player is on the ground, it gets stuck on false.

What I am trying to say is that I want a script that can detect when a player actually jumps and when a player actually hits the ground with bool-values.

Here is the script that “accurately” detects when a player jumps and hits the ground.

local char = script.Parent
local humanoid = char:FindFirstChild("Humanoid")

local onGround = script:WaitForChild("OnGround")
local Jumping = script:WaitForChild("Jumping")

humanoid.StateChanged:Connect(function(old, newstate)
	if newstate == Enum.HumanoidStateType.Jumping and Jumping.Value == false and onGround.Value == true then
		Jumping.Value = true
		onGround.Value = false
		print("jump")
	end
end)

humanoid.StateChanged:Connect(function(old, newstate)
	if newstate == Enum.HumanoidStateType.Landed and Jumping.Value == true and onGround.Value == false then
		Jumping.Value = false
		onGround.Value = true
		print("ground")
	end
end)

I need some help on this, it is okay if there is no solution whatsoever because this seems very difficult to try and resolve. Any help is appreciated.

2 Likes

well here ya go this worked for me

local char = script.Parent
local humanoid = char:FindFirstChild("Humanoid")

local onGround = script:WaitForChild("OnGround")
local Jumping = script:WaitForChild("Jumping")

humanoid.StateChanged:Connect(function(old, newstate)
	if newstate == Enum.HumanoidStateType.Jumping then
		Jumping.Value = true
		onGround.Value = false
		print("jump")
	end
end)

humanoid.StateChanged:Connect(function(old, newstate)
	if newstate == Enum.HumanoidStateType.Landed then
		Jumping.Value = false
		onGround.Value = true
		print("ground")
	end
end)

i just removed the 2 if statements on line 8 and 16

2 Likes

I don’t think it matters if you remove a couple of sections on line 8 and 16, I still tried what you did and it does not work.

The jumping bool-value’s value is stuck on true every time you hold space, while the onground value is stuck on false while space is being held.

Once you release space, it seems everything goes back to normal (Jumping value is false and OnGround value is true when space isn’t being held).

1 Like

If you connect a changed function to the boolvalues for testing purposes you’ll see that it is working, its just that the studio properties tab updates a little late. Nothing is wrong with your script.

Oh ok. Well, I used while task.wait() do and would be in a function that gets if the player has landed or jumped. It works instantly!

humanoid.StateChanged:Connect(function(old, newstate)
	if newstate == Enum.HumanoidStateType.Jumping then
		while task.wait() do
			jump_tag.Value = 0
			if jump_tag.Value == 1 then
				break
			end
		end
	elseif newstate == Enum.HumanoidStateType.Landed and old == Enum.HumanoidStateType.Freefall  then
		while task.wait() do
			jump_tag.Value = 1
			if jump_tag.Value == 0 then
				break
			end
		end
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.