Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i check if a player jumps?

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.

2 comments

1

you would have to make them sit then check everytime they go back to standing

0

This is false.

3 answers

✓ Accepted answer

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!

4 comments

0

the reason I included both parameters was so that if you wanted to use them both you could.

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.

0

Oh.

0

lol

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

5 comments

0

yea thats a better answer lol

0

isnt KeyDown deprecated?

0

Yes it's deprecated, use UserInputService

0

i did and it works

0

Make sure to accept and upvote :P

###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)

3 comments

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.

0

thanks, i was using a similar method but yours can repeat until im not jumping anymore which would be useful in my game

0

i just rewrote my script using your method and now the repeat isnt getting deactivated

This discussion is preserved as it was. New answers, comments, and votes are closed.