----------------------------------------------
local RS = char.RightUpperArm["RightShoulder"]
local LS = char.LeftUpperArm["LeftShoulder"]
local RH = char["RightUpperLeg"]:WaitForChild("RightHip")
local LH = char["LeftUpperLeg"]:WaitForChild("LeftHip")
local LeftLeg = char["LeftUpperLeg"]
local RightLeg = char["RightUpperLeg"]--[[
ttt = Instance.new("Weld",Character.Head)
ttt.Part0 = Character.Head
ttt.Part1 = Character.UpperTorso
--]]
function Stand()
	Humanoid.CameraOffset = Vector3.new(0, .7, 0)
	Humanoid.WalkSpeed = 16
	IsStanced = false	
	for i, s in pairs(Torso:GetChildren()) do
		if (s.Name == "LegWeld") and (s.ClassName == "Weld") then
			s:Destroy()
		end
	end
	LH.Part1 = LeftLeg
	RH.Part1 = RightLeg
	Proned2 = Vector3.new(0,0,0)
	tweenJoint(RootJoint, CFrame.new()* CFrame.Angles(math.rad(-0),0,math.rad(0)), CFrame.new(0,0,0), function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(RH, CFrame.new(.4,0,0)* CFrame.Angles(math.rad(0),math.rad(0),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0)
	tweenJoint(LH, CFrame.new(-.4,0,0)* CFrame.Angles(math.rad(0),math.rad(0),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0)
	tweenJoint(RS, CFrame.new(.85,0.5,0)* CFrame.Angles(math.rad(0),math.rad(0),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(LS, CFrame.new(-.85,0.5,0)* CFrame.Angles(math.rad(0),math.rad(-0),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
end

function LeanRight()
	Humanoid.CameraOffset = Vector3.new(0.5, -0.35, 0)
	Humanoid.WalkSpeed = 9
	IsStanced = true	
	Proned2 = Vector3.new(0,0,0)
	RH.Part1 = nil
	CreateWeld(RightLeg, CFrame.new(-0.2,1.85,0.3)* CFrame.Angles(math.rad(-0),0,math.rad(-20)))
	tweenJoint(RootJoint, CFrame.new(0.1,-0.25,0)* CFrame.Angles(math.rad(-0),0,math.rad(-20)), CFrame.new(0,0,0), function(X) return math.sin(math.rad(X)) end, 0.25)
end

function LeanLeft()
	Humanoid.CameraOffset = Vector3.new(-0.5, -0.35, 0)
	Humanoid.WalkSpeed = 9
	IsStanced = true	
	Proned2 = Vector3.new(0,0,0)
	LH.Part1 = nil
	CreateWeld(LeftLeg, CFrame.new(0.2,1.85,0.3)* CFrame.Angles(math.rad(-0),0,math.rad(20)))
	tweenJoint(RootJoint, CFrame.new(-0.1,-0.25,0)* CFrame.Angles(math.rad(-0),0,math.rad(20)), CFrame.new(0,0,0), function(X) return math.sin(math.rad(X)) end, 0.25)
end

function Crouch()
	Humanoid.CameraOffset = Vector3.new(0, -1, 0)
	Humanoid.WalkSpeed = 9
	for i, s in pairs(Torso:GetChildren()) do
		if (s.Name == "LegWeld") and (s.ClassName == "Weld") then
			s:Destroy()
		end
	end
	IsStanced = true	
	RH.Part1 = RightLeg
	LH.Part1 = LeftLeg
	Proned2 = Vector3.new(0,0,0)
	tweenJoint(RootJoint, CFrame.new(0,-1,0)* CFrame.Angles(math.rad(-0),0,math.rad(0)), CFrame.new(0,0,0), function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(RH, CFrame.new(1,-0.15,-0.65)* CFrame.Angles(math.rad(-20),math.rad(90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(LH, CFrame.new(-1,-0.675,-0.625)* CFrame.Angles(math.rad(-60),math.rad(-90),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(RS, CFrame.new(1,0.5,0)* CFrame.Angles(math.rad(0),math.rad(-45),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(LS, CFrame.new(-1,0.5,0)* CFrame.Angles(math.rad(0),math.rad(45),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
end

function Prone()
	Humanoid.CameraOffset = Vector3.new(0, -3.5, 0)
	Humanoid.WalkSpeed = 4
	IsStanced = true
	RH.Part1 = nil
	LH.Part1 = nil
	Proned2 = Vector3.new(0,0.5,0.5)
	tweenJoint(RootJoint, CFrame.new(0,-2.5,1)* CFrame.Angles(math.rad(-90),0,math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(RS, CFrame.new(0,0,0)* CFrame.Angles(math.rad(0),math.rad(0),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0.25)
	tweenJoint(LS, CFrame.new(0,0,0)* CFrame.Angles(math.rad(0),math.rad(0),math.rad(0)), nil, function(X) return math.sin(math.rad(X)) end, 0)
	CreateWeld(RightLeg, CFrame.new(-0.2,1.85,0)* CFrame.Angles(math.rad(-0),0,math.rad(-20)))
	CreateWeld(LeftLeg, CFrame.new(0.2,1.85,0)* CFrame.Angles(math.rad(-0),0,math.rad(20)))
end

local AlreadyProned = false
	mouse.KeyDown:connect(function(Key)
		if Key == "c" and Stances == 0 and not _G.Sprinting and not _G.Lean then
			Stances = 1
			Crouch()
			_G.Crouched = true
		elseif Key == "c" and Stances == 1 and not _G.Sprinting and not _G.Lean   then	
			Stances = 2
			Prone()
			_G.Crouched = false
			_G.Proned = true
			AlreadyProned = true
		elseif Key == "x" and Stances == 2 and not _G.Sprinting and not _G.Lean   then
			AlreadyProned = false	
			_G.Crouched = true
			_G.Proned = false
			Stances = 1
			Crouch()
		elseif Key == "x" and Stances == 1 and not _G.Sprinting and not _G.Lean   then		
			_G.Crouched = false
			Stances = 0
			Stand()
		end
		if Key == "e" and not _G.Lean and Stances == 0 and not _G.Sprinting  then
			LeanRight()
			_G.Lean = true
		end
		if Key == "q" and not _G.Lean and Stances == 0 and not _G.Sprinting   then
			LeanLeft()
			_G.Lean = true
		end
	end)
	mouse.KeyUp:connect(function(Key)
		if Key == "e" and _G.Lean and Stances == 0 and not _G.Sprinting   then
			Stand()
			_G.Lean = false
		end
		if Key == "q" and _G.Lean and Stances == 0 and not _G.Sprinting   then
			Stand()
			_G.Lean = false
		end
	end)
	
Stand()