local K={}local L={}local M={}local J=game:GetService("\080\108\097\121\101\114\115")local V=game:GetService("\082\117\110\083\101\114\118\105\099\101")local U=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")do local V=J.LocalPlayer K=setmetatable({},{__index=function(L)return rawget(K,L)or V:FindFirstChild(tostring(L))end})local function U(J)wait()K.character=J K.mouse=V:GetMouse()K.backpack=V:WaitForChild("\066\097\099\107\112\097\099\107")K.humanoid=K.character:WaitForChild("\072\117\109\097\110\111\105\100")K.torso=K.character:WaitForChild("\084\111\114\115\111")K.alive=true repeat wait()until K.humanoid.Parent==K.character and K.character:IsDescendantOf(game)M.crouch=K.humanoid:LoadAnimation(script:WaitForChild("\099\114\111\117\099\104"))L.stance="\115\116\097\110\100"local U U=K.humanoid.Died:connect(function()K.alive=false U:disconnect()if M.crouch then M.crouch:Stop(.2)end end)end if V.Character then U(V.Character)end V.CharacterAdded:connect(U)end do L.stance="\115\116\097\110\100"local J=false local c=CFrame.new(1,-1,0,0,0,1,0,1,0,-1,0,0)local d=CFrame.new(-1,-1,0,0,0,-1,0,1,0,1,0,0)V.RenderStepped:connect(function()if M.crouch then if M.crouch.IsPlaying then M.crouch:AdjustSpeed((Vector3.new(K.torso.Velocity.x,0,K.torso.Velocity.z)).magnitude/10)end end end)U.TextBoxFocused:connect(function()if J then J=false K.humanoid.WalkSpeed=16 end end)U.InputBegan:connect(function(V,U)if not U then if V.UserInputType==Enum.UserInputType.Keyboard then local U=V.KeyCode if U==Enum.KeyCode.C then if L.stance=="\099\114\111\117\099\104"then K.humanoid.HipHeight=0 K.humanoid.WalkSpeed=16 M.crouch:Stop(.2)L.stance="\115\116\097\110\100"else L.stance="\099\114\111\117\099\104"K.humanoid.HipHeight=-1 K.humanoid.WalkSpeed=6.4 M.crouch:Play(.2)end elseif U==Enum.KeyCode.LeftShift then if not J then J=true K.humanoid.WalkSpeed=16*(L.stance=="\099\114\111\117\099\104"and.8 or 1.25)end end end end end)U.InputEnded:connect(function(M,V)if not V then if M.UserInputType==Enum.UserInputType.Keyboard then local V=M.KeyCode if V==Enum.KeyCode.LeftShift then if J then J=false K.humanoid.WalkSpeed=16*(L.stance=="\099\114\111\117\099\104"and.4 or 1)end end end end end)end
-- this script is optional and not required to have, delete it or keep it

local player = {}
local input = {}
local animation = {}

local players = game:GetService("Players")
local runservice = game:GetService("RunService")
local userinput = game:GetService("UserInputService")

do -- player
	local PLAYER = players.LocalPlayer

	player = setmetatable({}, {
		__index = function(k)
			return rawget(player, k) or PLAYER:FindFirstChild(tostring(k))
		end,
	})

	local function onCharacter(character)
		wait()
		player.character = character
		player.mouse = PLAYER:GetMouse()
		player.backpack = PLAYER:WaitForChild("Backpack")
		player.humanoid = player.character:WaitForChild("Humanoid")
		player.torso = player.character:WaitForChild("Torso")
		player.alive = true

		repeat
			wait()
		until player.humanoid.Parent == player.character and player.character:IsDescendantOf(game)
		animation.crouch = player.humanoid:LoadAnimation(script:WaitForChild("crouch"))
		input.stance = "stand"
		local onDied
		onDied = player.humanoid.Died:connect(function()
			player.alive = false
			onDied:disconnect()
			if animation.crouch then
				animation.crouch:Stop(0.2)
			end
		end)
	end
	if PLAYER.Character then
		onCharacter(PLAYER.Character)
	end
	PLAYER.CharacterAdded:connect(onCharacter)
end

do -- input
	input.stance = "stand"
	local sprinting = false
	local default_right = CFrame.new(1, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
	local default_left = CFrame.new(-1, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
	runservice.RenderStepped:connect(function()
		if animation.crouch then
			if animation.crouch.IsPlaying then
				animation.crouch:AdjustSpeed(
					Vector3.new(player.torso.Velocity.x, 0, player.torso.Velocity.z).magnitude / 10
				)
			end
		end
	end)
	userinput.TextBoxFocused:connect(function()
		if sprinting then
			sprinting = false
			player.humanoid.WalkSpeed = 16
		end
	end)
	userinput.InputBegan:connect(function(object, g)
		if not g then
			if object.UserInputType == Enum.UserInputType.Keyboard then
				local key = object.KeyCode
				if key == Enum.KeyCode.C then
					if input.stance == "crouch" then
						player.humanoid.HipHeight = 0
						player.humanoid.WalkSpeed = 16
						animation.crouch:Stop(0.2)
						input.stance = "stand"
					else
						input.stance = "crouch"
						player.humanoid.HipHeight = -1
						player.humanoid.WalkSpeed = 16 * 0.4
						animation.crouch:Play(0.2)
					end
				elseif key == Enum.KeyCode.LeftShift then
					if not sprinting then
						sprinting = true
						player.humanoid.WalkSpeed = 16 * (input.stance == "crouch" and 0.8 or 1.25)
					end
				end
			end
		end
	end)
	userinput.InputEnded:connect(function(object, g)
		if not g then
			if object.UserInputType == Enum.UserInputType.Keyboard then
				local key = object.KeyCode
				if key == Enum.KeyCode.LeftShift then
					if sprinting then
						sprinting = false
						player.humanoid.WalkSpeed = 16 * (input.stance == "crouch" and 0.4 or 1)
					end
				end
			end
		end
	end)
end
