Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local JUMP_INTERVAL = 0.2;
- local rbx_userInputService = game:GetService("UserInputService");
- local rbx_players = game:GetService("Players");
- local player = rbx_players.LocalPlayer;
- local can_jump = false;
- local has_jumped = false;
- local character;
- local humanoid;
- local function OnCharacterAdded( newCharacter)
- character = newCharacter;
- humanoid = character:WaitForChild("Humanoid");
- humanoid.StateChanged:Connect(function( _, new_state )
- if new_state == Enum.HumanoidStateType.Landed then
- can_jump = false; has_jumped = false;
- elseif new_state == Enum.HumanoidStateType.Freefall then
- wait(JUMP_INTERVAL);
- can_jump = true;
- end
- end)
- end
- if player.Character then
- OnCharacterAdded(player.Character)
- end
- player.CharacterAdded:Connect(OnCharacterAdded)
- rbx_userInputService.JumpRequest:Connect(function()
- if not character or not humanoid then return end
- if can_jump and not has_jumped then
- has_jumped = true;
- humanoid:ChangeState(Enum.HumanoidStateType.Jumping);
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement