Advertisement
dried_

Double Jump Script | Roblox Studio

Apr 12th, 2021
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 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 oldPowerlocal TIME_BETWEEN_JUMPS = 0.1
  9. local DOUBLE_JUMP_POWER_MULTIPLIER = 1.5
  10.  
  11. function onJumpRequest()
  12. if not character or not humanoid or not character:IsDescendantOf(workspace) or
  13. humanoid:GetState() == Enum.HumanoidStateType.Dead then
  14. return
  15. end
  16.  
  17. if canDoubleJump and not hasDoubleJumped then
  18. hasDoubleJumped = true
  19. humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
  20. end
  21. end
  22.  
  23. local function characterAdded(newCharacter)
  24. character = newCharacter
  25. humanoid = newCharacter:WaitForChild("Humanoid")
  26. hasDoubleJumped = false
  27. canDoubleJump = false
  28. oldPower = humanoid.JumpPower
  29. humanoid.StateChanged:connect(function(old, new)
  30. if new == Enum.HumanoidStateType.Landed then
  31. canDoubleJump = false
  32. hasDoubleJumped = false
  33. humanoid.JumpPower = oldPower elseif new == Enum.HumanoidStateType.Freefall then
  34. wait(TIME_BETWEEN_JUMPS) canDoubleJump = true
  35. end
  36. end)
  37. end
  38.  
  39. if localPlayer.Character then
  40. characterAdded(localPlayer.Character)
  41. end
  42.  
  43. localPlayer.CharacterAdded:connect(characterAdded)
  44. UserInputService.JumpRequest:connect(onJumpRequest)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement