Advertisement
dubleeyrblxx

Double Jump -- Roblox

Aug 27th, 2022 (edited)
3,959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. local UserInputService = game:GetService("UserInputService")
  2. local player = game:GetService("Players").LocalPlayer
  3. local character = player.Character
  4. local humanoid = character:WaitForChild("Humanoid")
  5.  
  6. local MAX_JUMPS = 2
  7. local TIME_BETWEEN_JUMPS = 0.2
  8. local numJumps = 0
  9. local canJumpAgain = false
  10.  
  11. local function onStatChanged(oldState, newState)
  12.     if Enum.HumanoidStateType.Landed == newState then
  13.         numJumps = 0
  14.         canJumpAgain = false
  15.     elseif Enum.HumanoidStateType.Freefall == newState then
  16.         wait(TIME_BETWEEN_JUMPS)
  17.         canJumpAgain = true
  18.     elseif Enum.HumanoidStateType.Jumping  ==  newState then
  19.         canJumpAgain = false
  20.         numJumps += 1
  21.     end
  22.    
  23. end
  24.  
  25. local function onJumpRequest()
  26.     if canJumpAgain and numJumps < MAX_JUMPS then
  27.         humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
  28.     end
  29. end
  30.  
  31. humanoid.StateChanged:Connect(onStatChanged)
  32. UserInputService.JumpRequest:Connect(onJumpRequest)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement