Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Key bindings
- local jumpKey = Enum.KeyCode.Space
- local walkKey = Enum.KeyCode.W
- local crouchKey = Enum.KeyCode.LeftControl
- local runKey = Enum.KeyCode.LeftShift
- -- Walk and run speed
- local walkSpeed = 16
- local runSpeed = 24
- -- Crouch height
- local crouchHeight = 1.5
- -- Listen for player's input
- game:GetService("UserInputService").InputBegan:Connect(function(input, _)
- local player = game.Players.LocalPlayer
- if input.KeyCode == jumpKey then
- -- Implement jump behavior here (e.g., apply an upward force)
- -- Example: player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
- elseif input.KeyCode == walkKey then
- -- Set player's walkspeed to the walk speed
- player.Character.Humanoid.WalkSpeed = walkSpeed
- elseif input.KeyCode == crouchKey then
- -- Set player's walkspeed and height to crouch values
- player.Character.Humanoid.WalkSpeed = walkSpeed
- player.Character.Humanoid.CameraOffset = Vector3.new(0, -0.75, 0)
- player.Character.Humanoid.JumpPower = 0
- player.Character.Humanoid.AutoRotate = false
- player.Character.Humanoid.Crouch = true
- player.Character.Humanoid.CameraOffset = Vector3.new(0, -0.75, 0)
- player.Character.Humanoid.HipHeight = crouchHeight
- elseif input.KeyCode == runKey then
- -- Set player's walkspeed to the run speed
- player.Character.Humanoid.WalkSpeed = runSpeed
- end
- end)
- -- Reset player's state when keys are released
- game:GetService("UserInputService").InputEnded:Connect(function(input, _)
- local player = game.Players.LocalPlayer
- if input.KeyCode == walkKey or input.KeyCode == runKey then
- -- Set player's walkspeed back to default
- player.Character.Humanoid.WalkSpeed = 16
- elseif input.KeyCode == crouchKey then
- -- Reset player's crouch state
- player.Character.Humanoid.AutoRotate = true
- player.Character.Humanoid.Crouch = false
- player.Character.Humanoid.CameraOffset = Vector3.new(0, 0, 0)
- player.Character.Humanoid.HipHeight = 0
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement