Advertisement
Gametoy

w0t

Mar 2nd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. local UserInputService = game:GetService("UserInputService")
  2. local localPlayer = game.Players.LocalPlayer
  3. local character
  4. local humanoid
  5.  
  6. local canDoubleJump = false
  7. local hasDoubleJumped = false
  8. local oldPower
  9. local TIME_BETWEEN_JUMPS = 0.2
  10. local DOUBLE_JUMP_POWER_MULTIPLIER = 2
  11.  
  12. function onJumpRequest()
  13. if not character or not humanoid or not character:IsDescendantOf(workspace) or
  14. humanoid:GetState() == Enum.HumanoidStateType.Dead then
  15. return
  16. end
  17.  
  18. if canDoubleJump and not hasDoubleJumped then
  19. hasDoubleJumped = true
  20. humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER
  21. humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
  22. end
  23. end
  24.  
  25. local function characterAdded(newCharacter)
  26. character = newCharacter
  27. humanoid = newCharacter:WaitForChild("Humanoid")
  28. hasDoubleJumped = false
  29. canDoubleJump = false
  30. oldPower = humanoid.JumpPower
  31.  
  32. humanoid.StateChanged:connect(function(old, new)
  33. if new == Enum.HumanoidStateType.Landed then
  34. canDoubleJump = false
  35. hasDoubleJumped = false
  36. humanoid.JumpPower = oldPower
  37. elseif new == Enum.HumanoidStateType.Freefall then
  38. wait(TIME_BETWEEN_JUMPS)
  39. canDoubleJump = true
  40. end
  41. end)
  42. end
  43.  
  44. if localPlayer.Character then
  45. characterAdded(localPlayer.Character)
  46. end
  47.  
  48. localPlayer.CharacterAdded:connect(characterAdded)
  49. UserInputService.JumpRequest:connect(onJumpRequest)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement