Advertisement
oopsrainbow4

Double/Triple Jumps

Mar 3rd, 2023
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. -- Put it in StarterPlayer, StarterCharacterScript
  2.  
  3. local UserInputService = game:GetService("UserInputService") -- Detect user device like press button, mouse,...
  4. local player = game:GetService("Players").LocalPlayer
  5.  
  6. local character = player.Character
  7. local humanoid = character:WaitForChild("Humanoid")
  8.  
  9. local MAX_JUMPS = 3 -- Amounts Jumps in midair
  10. local TIME_BETWEEN_JUMPS = 0.2 -- Delay to jump again
  11. local numJumps = 0
  12. local canJumpAgain = false
  13.  
  14. local function onStateChanged(oldState, newState)
  15.     if Enum.HumanoidStateType.Landed == newState then
  16.         numJumps = 0
  17.         canJumpAgain = false
  18.     elseif Enum.HumanoidStateType.Freefall == newState then
  19.         wait(TIME_BETWEEN_JUMPS)
  20.         canJumpAgain = true
  21.     elseif Enum.HumanoidStateType.Jumping == newState then
  22.         canJumpAgain = false
  23.         numJumps += 1
  24.     end
  25. end
  26.  
  27. local function onJumpRequest()
  28.     if canJumpAgain and numJumps < MAX_JUMPS then
  29.         humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
  30.     end
  31. end
  32.  
  33. humanoid.StateChanged:Connect(onStateChanged)
  34. UserInputService.JumpRequest:Connect(onJumpRequest)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement