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 6 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:

01local JumpPower = 50
02local Player = script.Parent
03 
04while wait() do
05    if Player.Humanoid.jumping == true then
06        repeat
07            JumpPower = JumpPower + 0.01
08            Player.Humanoid.JumpPower = JumpPower
09            print(JumpPower)
10        until Player.Humanoid.jumping == false
11    end
12end

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 — 6y
0
This is false. SBlankthorn 329 — 6y

3 answers

Log in to vote
2
Answered by 6 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:

1player.Character.Humanoid.StateChanged:Connect(function(oldState, newState)
2 
3    -- if newState is jumping then go forward otherwise do nothing
4 
5end)

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 — 6y
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 — 6y
0
Oh. User#21908 42 — 6y
0
lol User#21908 42 — 6y
Ad
Log in to vote
0
Answered by 6 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 — 6y
0
isnt KeyDown deprecated? 20002000sa 83 — 6y
0
Yes it's deprecated, use UserInputService User#19524 175 — 6y
0
i did and it works 20002000sa 83 — 6y
0
Make sure to accept and upvote :P SBlankthorn 329 — 6y
Log in to vote
0
Answered by 6 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.

01local JumpPower = 50
02local Character = script.Parent
03 
04Character.Humanoid.Jumping:Connect(function(active) -- parameter is if they're still jumping
05    repeat
06        JumpPower = JumpPower + 0.01
07        Character.Humanoid.JumpPower = JumpPower
08        print(JumpPower)
09    until not active -- repeat until stop jumping
10end)
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 — 6y
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 — 6y
0
i just rewrote my script using your method and now the repeat isnt getting deactivated 20002000sa 83 — 6y

Answer this question