Trying to detect if other players jumped

Im trying to make a code that detects whenever another player jumps. The problem is that when the other player resets it messes up the code.

Atempt:

function BlockWatcher(char)
	local hum = char.Humanoid
	hum:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
		if hum.FloorMaterial == Enum.Material.Air  then -- Jumped
			print("JUMPED")
		elseif hum.FloorMaterial ~= Enum.Material.Air then -- Landed	
			print("Landed")
		end
	end)
end

for i,v in ipairs(game.Players:GetPlayers()) do
	BlockWatcher(v.Character) 
	v.CharacterAdded:Connect(function(Char)
		BlockWatcher(Char)
	end)
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		BlockWatcher(char)
	end)
end)

but when the character resets, it doesn’t apply to them any more. How do I fix that?

1 Like

You should probably change this to

for i,v in ipairs(game.Players:GetPlayers()) do
	BlockWatcher(v.Character or v.CharacterAdded:wait()) 
	v.CharacterAdded:Connect(function(Char)
		BlockWatcher(Char)
	end)
end

Is there any errors showing in the output?

1 Like

Why this complicated process? Just do this:

humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Jumping then
   -- ur stuff
1 Like

But I need it for every character not just the players

No the issue is after the other players reset, it stops working on their characters

Well i need to detect when the player lands that’s why

Landed is a HumanoidStateType.

Your code works completely fine for me even if the player resets.

Why couldn’t you just do

local Players = game:GetService("Players")

local function CharAdded(Char)
    local Humanoid = Character:WaitForChild("Humanoid")

    Humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
        if Humanoid.Jump == true then
            print(Char.Name, "Jumped")
        else
            print(Char.Name, "Landed")
        end
    end)
end

game.Players.PlayerAdded:Connect(function(Plr)
    Plr.CharacterAdded:Connect(CharAdded)
end)

The only issue that I could see is where the script actually is, cause there are some locations where some scripts can’t fully run

Humanoid.Jumping seems to miss most of the jumps when testing your script.

Strange, I’ve never really had any issues with a delay from that (Thanks ROBLOX)

Not sure if using GetPropertyChangedSignal("Jump") would result in the same outcome, it’s strange how some Events aren’t just designed to work properly as expected

the problem is that its a local script, so how can I get all players current and future

Why couldn’t you just do this as a regular script inside ServerScriptService? It would work exactly the same & it’ll be server-sided as well, so you could check for when a Character starts to jump

State changes replicate. Just use a Server Script to accomplish this. If you intend to hook this to each player that joins, make good use of StarterCharacterScripts with a server script and you can pull what you want to achieve there.

If you’re trying to implement specific checks that usually only 1 script would do, have a configuration somewhere in the game, for example dying on jump and set the script for that one player to listen to it.

For example, if the BoolValue was true, kill them if a State change to “Jumping” is true.