Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I detect if the player jumped?

Asked by
p0vd 207 Moderation Voter
4 years ago

I'm not sure if Jump is boolean value because this doesn't seem to work.

local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

if humanoid.Jump.Value == true then
    print("the player has jumped")
end

1 answer

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
4 years ago

You are very close, try this:

Player = game.Players.LocalPlayer
Character = Player.Character or Player.CharacterAdded:Wait()

Humanoid = Character:WaitForChild('Humanoid')

local isJumping = false

Humanoid.StateChanged:Connect(function(oldState, newState)
    if newState == Enum.HumanoidStateType.Jumping then
        if not isJumping then
            isJumping = true
        end
    elseif newState == Enum.HumanoidStateType.Landed then
        if isJumping then
            isJumping = false
        end
    end
end)

This uses StateChanged to detect when a player has started to jump, and when the player has landed.

Ad

Answer this question