Advertisement
HowToRoblox

DoubleJumpHandler

Jun 8th, 2020
4,797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.77 KB | None | 0 0
  1. local character = script.Parent
  2. local humanoid = character:WaitForChild("Humanoid")
  3.  
  4. local uis = game:GetService("UserInputService")
  5.  
  6. local canDoubleJump = false
  7. local hasLanded = true
  8.  
  9.  
  10. humanoid.StateChanged:Connect(function(previous, new)
  11.    
  12.     if new == Enum.HumanoidStateType.Jumping and hasLanded then
  13.        
  14.         if not canDoubleJump then canDoubleJump = true; hasLanded = false end
  15.        
  16.        
  17.     elseif new == Enum.HumanoidStateType.Landed then
  18.        
  19.         canDoubleJump = false
  20.         hasLanded = true
  21.     end
  22. end)
  23.  
  24. uis.InputBegan:Connect(function(input, processed)
  25.    
  26.     if processed then return end
  27.    
  28.     if input.KeyCode == Enum.KeyCode.Space then
  29.        
  30.         if canDoubleJump then
  31.            
  32.             humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
  33.             canDoubleJump = false
  34.         end
  35.     end
  36. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement