How to detect a player's jump while they are jumping?

I have a module that handles player stamina, it works for running, jumping and other miscellaneous actions. The jump action is a bit tricky though. It does detect jumps but the issue is it can only detect them after the jump has completed. Maybe it’s a bit nit-picky but I would like it to register the jump as it’s happening.

I know I could solve this by checking via client-side but I want to perform server-sided checks so that it’s less exploitable. If anyone has a method I could try let me know.

Here is what I a doing currently:

function module.handleMovement(player)
	local char = player.Character or player.CharacterAdded:Wait()
	local hum = char:FindFirstChild("Humanoid")
	local jumped = false
	hum.StateChanged:Connect(function(old, new)
		if (old == Enum.HumanoidStateType.Freefall and new == Enum.HumanoidStateType.Running) or (old == Enum.HumanoidStateType.Freefall and new == Enum.HumanoidStateType.Landed) then
			module.completeAction(player, "Jump")
		end
	end)
end
1 Like

Doesn’t the Humanoid already have a Jump value?
image

1 Like

It is not replicated.

That’s why it’s a lot more difficult.

You can send a RayCast downwards from the HumRootPart or Torso of the character.

Good idea, I will try that.

I guess it will just take stamina if the player is flung or launched

2 Likes

Could you register the jump command input (space bar, whatever) and use that?

That would be a client-side check, that is what I am trying to avoid.

Try the Humanoid.Jumping Event, there’s also a Jumping HumanoidStateType, try either of those.

I’ve tried using the jump event on the server or checking the humanoidstatetype before, a lot of the time it doesn’t fire and it’s super annoying.

1 Like

Roblox recommends detecting changes like that client-side, unfortunately I’m unsure of what you could do since you’re detecting those changes server-side. You could try a RemoteEvent when they jump to tell the server, but that’s about all I can recommend.

That’s the issue, that’s easily exploitable.
The only way to ensure it is secure is by doing server-sided checks

The client is very vulnerable, however, you could always check it server-side as well, or maybe use some type of hash and key? :thinking:

I am a little confused by what u are saying. Would you be able to elaborate?

1 Like

OP already said they want to do server side checks. Also please never use key systems. Server side checks and proper remote programming means you don’t need keys and exploiters can easily find the key and bypass it. Keys also inflate network usage.

1 Like

The hash and keys was a joke, add a little salt into it as well. I don’t see why something as simple as a player jumping is a vulnerability, however I am not sure what OP is trying to achieve. Anything to do with the client should always be checked with the client if you want reliability.

1 Like

I just fixed my issue.

For anyone else struggling with this here is a module I made.
I still have to do more testing but so far is seems very reliable.

local module = {}

module.HasLanded = {}

module.RegisterPlayer = function(self,player)
	coroutine.wrap(function()
		while true do
			if player.Character then
				local root = player.Character.HumanoidRootPart
				local start = root.Position
				local direction = -(root.CFrame.UpVector*20)
				local ray = Ray.new(start,direction)
				local part,hitPos = workspace:FindPartOnRay(ray,player.Character)
				if (root.Position-hitPos).magnitude >= 7 then
					if module.HasLanded[player] ~= false then
						module.HasLanded[player] = false
						print(player.Name.." has jumped")
					end
				else
					if module.HasLanded[player] == false then
						print(player.Name.." has landed")
					end
					module.HasLanded[player] = true
				end
			end
			wait()
		end
	end)()
end

return module
6 Likes

This might me easier

If Humanoid.FloorMaterial == Enum.FloorMaterial.Air then
---do stuff
end
2 Likes