Script That Detects When Humanoid Jumps/Moves, etc/

Hey Devs! I ran into some trouble when trying to have a server script detect whenever a player jumps or walks/moves.

FYI: I placed the server script into the server script service.

What should I do to the script to make it work and not get the output of an attempt to index nil with ‘Character.’ I believe this form of code used to work… I could rewrite the script to detect animation wise of when the player moves/jumps… however, I keep getting lost.

I haven’t script in awhile and feel a little lost!

Thoughts and Thx,
Nick:)

2 Likes

Is this a serverscript or localscript?

Try this!

local character = player.Character or Player.CharacterAdded:Wait()

This bit of code checks if the player has a character, and if it doesn’t it waits until it does.

Add a WaitForChild by the humanoid as well: local humanoid = character:WaitForChild("Humanoid").
This means that if the Humanoid hasn’t spawned in by the time the script has run, it will wait for it to spawn in.

Remove your while true do loop, you don’t need it because GetPropertyChangedSignal will fire whenever the humanoid is updated, you don’t need to have it in a loop.

Hope that this could help! :smiley:

(p.s if this is in a server script it won’t work because LocalPlayer can only be accessed via a local script, which is what I think @Katrist was getting at)

2 Likes

Make a serverscript and paste this code into it:

--//Functions
game:GetService("Players").PlayerAdded:Connect(function(player) -- Fires when the player joins
	player.CharacterAdded:Connect(function(character) -- Fires when the player's character loads
		character.Humanoid:GetPropertyChangedSignal("Jump"):Connect(function() -- Fires when the player's character's jump value changes
			if character.Humanoid.Jump == true then -- Checks if the jump value is true (so it doesn't kick the player again if the server lags and the player's value changes back to false)
				player:Kick("You Jumped!") -- Kicks the player
			end
		end)
	end)
end)

I’ve tested it and it works.

3 Likes
local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(key, processed)
	if processed then
		return
	end
	if key.KeyCode == Enum.KeyCode.Space then
		print("Jumped!")
	end
end)

As primitive as it gets, local script inside StarterPlayerScripts folder (assuming you wanted this to work in a local script).

It works perfectly! THANKS:)
One question… if I wanted to kick the player from them moving forward/backward etc, how would I do so?

1 Like

Like, kick them if they walk?

If so switch the code I gave first with this:

--//Services
local Players = game:GetService("Players")

--//Functions
Players.PlayerAdded:Connect(function(player) 
	player.CharacterAdded:Connect(function(character) 
		character.Humanoid:GetPropertyChangedSignal("Jump"):Connect(function() -- Kicks the player for jumping
			if character.Humanoid.Jump == true then 
				player:Kick("You Jumped!") 
			end
		end)
		
		character.Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()  -- Kicks the player for walking
			if character.Humanoid.MoveDirection.Magnitude > 0 then 
				player:Kick("You Walked!") 
			end
		end)
	end)
end)
1 Like

Keep in mind that most changes in the Humanoid do not replicate to the server. And if you’re doing this in the client it can easily be bypassed by exploiters.

The ones that I reference in the script do replicate to the server though.

This is a server script as you can see by Players.PlayerAdded