Advertisement
Guest User

Double jump script

a guest
Jan 26th, 2021
1,723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. --script made by gavdingo
  2. --youtube: Boss Developer
  3.  
  4. local plr = game.Players.LocalPlayer --gets player
  5. plr.CharacterAdded:Connect(function(char) --dectects when character loads
  6. --defining variables
  7. local hum = char:WaitForChild("Humanoid")
  8. local jumped = false
  9. local inputservice = game:GetService("UserInputService")
  10.  
  11. inputservice.InputBegan:Connect(function(i)
  12. --detects if spacebar is pressed
  13. if i.KeyCode == Enum.KeyCode.Space then
  14. local state = hum:GetState()
  15. if jumped == false and state == Enum.HumanoidStateType.Freefall then --checks if player is in air and has not double jumped yet
  16. jumped = true --setting debounce
  17. hum:ChangeState(Enum.HumanoidStateType.Jumping) --jumps the player
  18. end
  19. end
  20. end)
  21.  
  22. hum.StateChanged:Connect(function(old, new)
  23. if new == Enum.HumanoidStateType.Landed then --restes rebounce when player lands back on the ground
  24. jumped = false
  25. end
  26. end)
  27. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement