When player jumps do something

Hello!

I’m working on a new game, and I need to find out how to do something (I mean fire a remote event to the server) when the player jumps.

I tried to do it when you press space bar but you can just spam it without waiting the time for the jump.

All help appreciated!

1 Like
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		
		if humanoid then
			humanoid.Jumping:Connect(function()
				-- Your Code Here
			end)
		end
	end)
end)

2 Likes

What exactly are you trying to achieve?

not very In-depth explanation:

A player presses space bar
Fire the event
Server script receives the event
Add 1 jump to leaderstats

2 Likes

inspired by @AkexinxYedek

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		
		if humanoid then
			humanoid.Jumping:Connect(function()
				player.leaderstats.LEADERSTATNAME.Value += 1
			end)
		end
	end)
end)
1 Like

https://developer.roblox.com/en-us/api-reference/event/UserInputService/JumpRequest

Bruh he stole my script but whatever.

Where do I put this script? its local right

Do you want to be this local? (character limit)

This script have to in ServerScriptService.

Yeah it is supposed to fire a remoteevent to the server and add leaderstats on server

Edit: nevermind

Sometimes it would not detect humanoid is jumping.

If that happenes to you, try this:

Jumping = false

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		
		if humanoid then
			humanoid.Changed:Connect(function()
				if humanoid.Jump and not Jumping then
					Jumping = true
					player.leaderstats.LEADERSTATNAME.Value += 1
				end
			end)
			
			humanoid.FreeFalling:Connect(function()
				if Jumping then
					Jumping = false
				end
			end)
		end
	end)
end)

Yeah, ill try it and see if it works

1 Like

lol this is so true and unfair :wink: