Advertisement
CBBG_DEV

Roblox Double Jump Script

May 29th, 2019
5,772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1. -- DOUBLE JUMPING SCRIPT --
  2.  
  3. local UserInputService = game:GetService("UserInputService")
  4. local localPlayer = game.Players.LocalPlayer
  5. local character
  6. local humanoid
  7.  
  8. local canDoubleJump = false
  9. local hasDoubleJumped = false
  10. local oldPowerlocal TIME_BETWEEN_JUMPS = 0.1 -- Put time limit here
  11. local DOUBLE_JUMP_POWER_MULTIPLIER = 1       -- Put jump force here it doubl the old jump ex if your old jump is 20 it will double it
  12.  
  13. function onJumpRequest()
  14.     if not character or not humanoid or not character:IsDescendantOf(workspace) or
  15.      humanoid:GetState() == Enum.HumanoidStateType.Dead then
  16.         return
  17.     end
  18.  
  19.     if canDoubleJump and not hasDoubleJumped then
  20.         hasDoubleJumped = true
  21.         humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER        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.     humanoid.StateChanged:connect(function(old, new)
  32.         if new == Enum.HumanoidStateType.Landed then
  33.             canDoubleJump = false
  34.             hasDoubleJumped = false
  35.             humanoid.JumpPower = oldPower       elseif new == Enum.HumanoidStateType.Freefall then
  36.             wait(TIME_BETWEEN_JUMPS)            canDoubleJump = true
  37.         end
  38.     end)
  39. end
  40.  
  41. if localPlayer.Character then
  42.     characterAdded(localPlayer.Character)
  43. end
  44.  
  45. localPlayer.CharacterAdded:connect(characterAdded)
  46. UserInputService.JumpRequest:connect(onJumpRequest)
  47. --CBBG_DEV--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement