Advertisement
Byron201

make crouch,jump,walk,and run like free fire(continued)

Dec 7th, 2023
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.09 KB | Gaming | 0 0
  1. -- Key bindings
  2. local jumpKey = Enum.KeyCode.Space
  3. local walkKey = Enum.KeyCode.W
  4. local crouchKey = Enum.KeyCode.LeftControl
  5. local runKey = Enum.KeyCode.LeftShift
  6.  
  7. -- Walk and run speed
  8. local walkSpeed = 16
  9. local runSpeed = 24
  10.  
  11. -- Crouch height
  12. local crouchHeight = 1.5
  13.  
  14. -- Listen for player's input
  15. game:GetService("UserInputService").InputBegan:Connect(function(input, _)
  16.     local player = game.Players.LocalPlayer
  17.  
  18.     if input.KeyCode == jumpKey then
  19.         -- Implement jump behavior here (e.g., apply an upward force)
  20.         -- Example: player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
  21.     elseif input.KeyCode == walkKey then
  22.         -- Set player's walkspeed to the walk speed
  23.         player.Character.Humanoid.WalkSpeed = walkSpeed
  24.     elseif input.KeyCode == crouchKey then
  25.         -- Set player's walkspeed and height to crouch values
  26.         player.Character.Humanoid.WalkSpeed = walkSpeed
  27.         player.Character.Humanoid.CameraOffset = Vector3.new(0, -0.75, 0)
  28.         player.Character.Humanoid.JumpPower = 0
  29.         player.Character.Humanoid.AutoRotate = false
  30.         player.Character.Humanoid.Crouch = true
  31.         player.Character.Humanoid.CameraOffset = Vector3.new(0, -0.75, 0)
  32.         player.Character.Humanoid.HipHeight = crouchHeight
  33.     elseif input.KeyCode == runKey then
  34.         -- Set player's walkspeed to the run speed
  35.         player.Character.Humanoid.WalkSpeed = runSpeed
  36.     end
  37. end)
  38.  
  39. -- Reset player's state when keys are released
  40. game:GetService("UserInputService").InputEnded:Connect(function(input, _)
  41.     local player = game.Players.LocalPlayer
  42.  
  43.     if input.KeyCode == walkKey or input.KeyCode == runKey then
  44.         -- Set player's walkspeed back to default
  45.         player.Character.Humanoid.WalkSpeed = 16
  46.     elseif input.KeyCode == crouchKey then
  47.         -- Reset player's crouch state
  48.         player.Character.Humanoid.AutoRotate = true
  49.         player.Character.Humanoid.Crouch = false
  50.         player.Character.Humanoid.CameraOffset = Vector3.new(0, 0, 0)
  51.         player.Character.Humanoid.HipHeight = 0
  52.     end
  53. end)
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement