Count each time a character jumps - most methods fail?

we are working on stamina for jumping, we want to take away 10 stamina for each jump.

However, there is no clear way to tell (why?) when a roblox character jumps.

  1. work off keypress - this works, using User Input Service and detecting which key was pressed. Trouble is, it will only remove for the first jump, if you hold the jump key down (spacebar). We need -10 each jump

  2. work off humanoid property changed signal - this takes off MANY -10 stamina points, because for a SINGLE JUMP it enters the “jump” state 9 or 10 times… (why?!)… we checked it with a print statement attached to the humanoid.changed.

Is there any clear way to tell each time a roblox character jumps (counting each jump as only “1” jump…but counting each and every jump ?)

If we use this print statement:

Humanoid.Changed:Connect(function(changedProperty)
print(changedProperty)
end)

We press spacebar and get a readout of:

Jumped
JumpReplicated
Jumped
JumpReplicated
Jumped
Floor Material (??! WTH?)
Jumped
JumpReplicated
FloorMaterial

So why does it print “floor material” as a humanoid changed property?

And why in the MIDDLE of the jump, when he touches nothing but air?

???

Please don’t post anything you haven 't used yourself. There are tons of answers we have tried from the forums already that didn’t work…please don’t repost anything you haven’t used)*

We’ve been troubleshooting this a while. thanks !

4 Likes

you can try doing something along the lines of this

all you have to do is adjust the “Tricky_Time_I_Need_To_Figure_Out” variable until it looks natural



local uis = game:GetService("UserInputService")

local Holding_Space = false
local Tricky_Time_I_Need_To_Figure_Out = 2




--determine when player tries to jump
uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Space then
		Holding_Space = true
	end
end)




--determine when player releases jump key
uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Space then
		Holding_Space = false
	end
end)


--this doesnt need to be wrapped in a coro if you dont want
coroutine.resume(coroutine.create(function()
	while true do
		if Holding_Space == true then
			--subtract 10 stamina
			wait(Tricky_Time_I_Need_To_Figure_Out)
		else 
			wait(.1)
		end
	end
end))




5 Likes

Thanks very much for the response. Unfortunately, we are looking for something more exact than guessing the number of seconds for a jump. A game engine should know when a jump begins and ends; we are certain roblox must have an accurate way to count jumps because it would be bizzaro world if you couldn’t tell when your character began and ended a jump in a game engine. We appreciate your help, thanks ~!

2 Likes

Could you not attach a :GetPropertyChangedSignal(“Jumped”) onto the Humanoid object in the character? I remember this not working right server-side so you might need to use this on the client.

Like so:

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
if not Humanoid then Humanoid = Instance.new("Humanoid") Humanoid.Parent = Character

Humanoid:GetPropertyChangedSignal("Jumping"):Connect(function() 
if Humanoid.Jumping then
-- They jumped!
end
end)
2 Likes

The FloorMaterial is a property that indicates the material on which the humanoid is standing (Terrain and parts). You can utilize this property to track instances where the humanoid is in the air. Alternatively, you can track the humanoid’s jump state and ensure that only one of these occurrences is counted.

1 Like

On my phone at the moment so that code is untested from the top of my head. Should work for you though. :slight_smile:

2 Likes
repeat task.wait(.1) until game:GetService("Players").LocalPlayer.Character and game:GetService("Players").LocalPlayer.Character.Humanoid

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")

Humanoid:GetPropertyChangedSignal("Jump"):Connect(function() 
	if Humanoid:GetState() == Enum.HumanoidStateType.Jumping then
		print("Look they are jumping rn how exciting!")
	end
end)

This would work but it fires double some times

1 Like

Thank you for your response! Sorry friend, as stated in original post, this actually triggers MANY times on a single jump.

Out put looks like this, if I use a print statement to print the humanoid property every time it changes, it prints the below, FOR A SINGLE JUMP:

Jumped
Jump Replicated
Jumped
Jumped
Jump Replicated
Jumped
Floor Material

This means it takes 10 from Stamina many times for a single jump.

Thank you for your response.


For future responses, please only respond with tested possibilities. The forum is full of answers that did not work when tested. Thank you for your response !

At that point, you could set a debounce for the player specifically where the inner method (where we check for jump to be true) doesn’t apply.

Still, using a remote for a stamina system is not a good idea. I am trying to find a solution.

Can’t you detect jumping with humanoid.Jumping event?
(didn’t read the entire post sorry if i sound dumb)

I think property changed singalling that FloorMaterial would work as you suggested @ali432567 to be honest, as that won’t change multiple times, unlike Jump.

But that’s still not secure as it is not replicated I am trying to find a method or property that is replicated that we can use for this

You could do some verification by signalling a remote when a jump is detected (when FloorMaterial is Enum.FloorMaterial.Air) via a RemoteEvent then handling some stuff on the server, for example, you could store when a player last jumped on the server and whether their ‘jump’ is valid? Don’t think detecting jump is replicated to the server to be honest, think it’s a client-owned thing.

Thank you for your solution! we are currently looking for accurate solutions that only show 1 jump for each single jump.

We really appreciate your response !

1 Like
local Humanoid = script.Parent:WaitForChild("Humanoid")

Humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Jumping then
		print("Player jumped")
	end
end)

i tested it and it should work. it prints one time per jump and also accounts for holding spacebar.

2 Likes

the issue isn’t an exploiter firing a remote the issue is it not firing since it reduces stamina exploiters would make it not fire and not lose stamina

1 Like

Thanks - we did some pseudocode on a clipboard and some research, and are going to work this direction. If we get it to work we will let you know. We are basically going to:

  1. watch for humanoid property to change, once it does:
  2. check if global isAlreadyJumping is false, if so, check if humanoid is jumping, if so:
  3. set isAlreadyJumping to true (special debounce global)
  4. remove 10 from stamina
    –
  5. if humanoid state changes, and isAlreadyJumping is true,
  6. check if humanoid property is “floor material”
  7. if its floor material, check if its “air”
  8. if is not air, set global isAlreadyJumping to false

that’s what we are trying - tomorrow. let you know if it works.

Thanks all !

2 Likes

Then using methods to detect the player jumping as suggested isn’t a possibility, as that would be the ultimate source of truth to detect whether a player jumped.

It’s sketchy, and I wouldn’t advocate these methods by all means, but you could detect it on the server, you could check to see whether they’re so much off of the ground, or if the character is touching something other than the parts it owns/in its hierarchy? But all of these aren’t accurate, as you could technically jump on the Z or X axis in world space depending on if you have a rotated world, and as for the touching parts, if you had a ceiling, it would detect as you not jumping suddenly.

1 Like

We will try this tomorrow, before trying the idea we just postedin pseudocode - thank you for your response ! We will test it Wednesday

1 Like