Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.02 KB | None | 0 0
  1. local JUMP_INTERVAL = 0.2;
  2.  
  3. local rbx_userInputService = game:GetService("UserInputService");
  4. local rbx_players = game:GetService("Players");
  5.  
  6. local player = rbx_players.LocalPlayer;
  7.  
  8. local can_jump = false;
  9. local has_jumped = false;
  10.  
  11. local character;
  12. local humanoid;
  13.  
  14. local function OnCharacterAdded( newCharacter)
  15.     character = newCharacter;
  16.     humanoid = character:WaitForChild("Humanoid");
  17.    
  18.     humanoid.StateChanged:Connect(function( _, new_state )
  19.         if new_state == Enum.HumanoidStateType.Landed then
  20.             can_jump = false; has_jumped = false;
  21.         elseif new_state == Enum.HumanoidStateType.Freefall then
  22.             wait(JUMP_INTERVAL);
  23.             can_jump = true;
  24.         end
  25.     end)
  26. end
  27.  
  28. if player.Character then
  29.     OnCharacterAdded(player.Character)
  30. end
  31.  
  32. player.CharacterAdded:Connect(OnCharacterAdded)
  33.  
  34. rbx_userInputService.JumpRequest:Connect(function()
  35.     if not character or not humanoid then return end
  36.    
  37.     if can_jump and not has_jumped then
  38.         has_jumped = true;
  39.         humanoid:ChangeState(Enum.HumanoidStateType.Jumping);
  40.     end
  41. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement