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


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(.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(.2)
						input.stance = "stand"
					else
						input.stance = "crouch"
						player.humanoid.HipHeight = -1
						player.humanoid.WalkSpeed = 16 * 0.4
						animation.crouch:Play(.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
