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

How do i check if a player jumps?

Asked by 5 years ago

I have a game where i want players to have a higher jump power everytime they jump but my script isn't working right. Can somebody help me? This is my script:

local JumpPower = 50
local Player = script.Parent

while wait() do
    if Player.Humanoid.jumping == true then
        repeat
            JumpPower = JumpPower + 0.01
            Player.Humanoid.JumpPower = JumpPower
            print(JumpPower)
        until Player.Humanoid.jumping == false
    end
end

But when i jump for some reason if Player.humanoid.jumping == true then is always false. This is the full script.

1
you would have to make them sit then check everytime they go back to standing retracee 68 — 5y
0
This is false. SBlankthorn 329 — 5y

3 answers

Log in to vote
2
Answered by 5 years ago

Hey check this link out. It is always more advisable to use an event than a loop. The way you can implement this is thus:

player.Character.Humanoid.StateChanged:Connect(function(oldState, newState)

    -- if newState is jumping then go forward otherwise do nothing

end)

Hope this helps and have a great day scripting!

0
the reason I included both parameters was so that if you wanted to use them both you could. User#21908 42 — 5y
0
This can work, however I don't think OP wants to go through the hassle of checking their HumanoidStateType every time it changes. This can be if they are swimming, or sitting. User#19524 175 — 5y
0
Oh. User#21908 42 — 5y
0
lol User#21908 42 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Make a KeyDown Event with the Space Key, and in the event do what you want it to do if it's pressed.

0
yea thats a better answer lol retracee 68 — 5y
0
isnt KeyDown deprecated? 20002000sa 83 — 5y
0
Yes it's deprecated, use UserInputService User#19524 175 — 5y
0
i did and it works 20002000sa 83 — 5y
0
Make sure to accept and upvote :P SBlankthorn 329 — 5y
Log in to vote
0
Answered by 5 years ago

There is a property and an event that can do this. I will use the event, as using loops to check for something is a bad practice.

local JumpPower = 50
local Character = script.Parent

Character.Humanoid.Jumping:Connect(function(active) -- parameter is if they're still jumping
    repeat
        JumpPower = JumpPower + 0.01
        Character.Humanoid.JumpPower = JumpPower
        print(JumpPower)
    until not active -- repeat until stop jumping 
end)

0
Your answer is obviously better. I see now what you mean. I did not know there was a specific event for jumping. Thanks for making me aware. User#21908 42 — 5y
0
thanks, i was using a similar method but yours can repeat until im not jumping anymore which would be useful in my game 20002000sa 83 — 5y
0
i just rewrote my script using your method and now the repeat isnt getting deactivated 20002000sa 83 — 5y

Answer this question