function Stand(s)local N=Torso["\076\101\102\116 \072\105\112"]local g=Torso["\082\105\103\104\116 \072\105\112"]LLegWeld.Part1=nil N.Part1=LLeg RLegWeld.Part1=nil g.Part1=RLeg Stance=0 spreadStance="\083\116\097\110\100"baseSpread=S.spreadSettings[spreadZoom][spreadStance][spreadMotion]if S.stanceSettings.Anim and not s then spawn(function()local s=stanceSway local N=0 local g=1.5/S.stanceSettings.Speed while true do RS.RenderStepped:wait()local b=N+g N=b>90 and 90 or b if Stance~=0 then break end stanceSway=numLerp(s,1,Sine(N))if N==90 then break end end end)tweenJoint(ABWeld,CF(),nil,Sine,S.stanceSettings.Speed)tweenJoint(LLegWeld,legC0.Stand[1],nil,Sine,S.stanceSettings.Speed)tweenJoint(RLegWeld,legC0.Stand[2],nil,Sine,S.stanceSettings.Speed)tweenJoint(N,CF(-1,-1,0)*CFANG(0,RAD(-90),0),CF(-0.5,1,0)*CFANG(0,RAD(-90),0),Sine,S.stanceSettings.Speed)tweenJoint(g,CF(1,-1,0)*CFANG(RAD(-180),RAD(90),0),CF(.5,1,0)*CFANG(RAD(-180),RAD(90),0),Sine,S.stanceSettings.Speed)tweenJoint(Root,CFANG(RAD(-90),0,RAD(180)),nil,Sine,S.stanceSettings.Speed)tweenJoint(headWeld,CF(0,1.5,0),nil,Sine,S.stanceSettings.Speed)elseif s or not S.stanceSettings.Anim then ABWeld.C0=CF()LLegWeld.C0=legC0.Stand[1]RLegWeld.C0=legC0.Stand[2]N.C0,N.C1=CF(-1,-1,0)*CFANG(0,RAD(-90),0),CF(-0.5,1,0)*CFANG(0,RAD(-90),0)g.C0,g.C1=CF(1,-1,0)*CFANG(RAD(-180),RAD(90),0),CF(.5,1,0)*CFANG(RAD(-180),RAD(90),0)Root.C0=CFANG(RAD(-90),0,RAD(180))headWeld.C0=CF(0,1.5,0)end end function Crouch()local s=Torso["\076\101\102\116 \072\105\112"]local N=Torso["\082\105\103\104\116 \072\105\112"]s.Part1=nil LLegWeld.Part1=LLeg N.Part1=nil RLegWeld.Part1=RLeg Stance=1 spreadStance="\067\114\111\117\099\104"baseSpread=S.spreadSettings[spreadZoom][spreadStance][spreadMotion]if S.stanceSettings.Anim then spawn(function()local s=stanceSway local N=0 local g=1.5/S.stanceSettings.Speed while true do RS.RenderStepped:wait()local b=N+g N=b>90 and 90 or b if Stance~=1 then break end stanceSway=numLerp(s,.75,Sine(N))if N==90 then break end end end)tweenJoint(ABWeld,CF(0,0,-0.05),nil,Sine,S.stanceSettings.Speed)tweenJoint(LLegWeld,legC0.Crouch[1],nil,Sine,S.stanceSettings.Speed)tweenJoint(RLegWeld,legC0.Crouch[2],nil,Sine,S.stanceSettings.Speed)tweenJoint(s,CF(-1,-0.5,0)*CFANG(0,RAD(-90),0),CF(-0.5,.5,1)*CFANG(0,RAD(-90),RAD(-90)),Sine,S.stanceSettings.Speed)tweenJoint(N,CF(1,-0.5,.25)*CFANG(RAD(-180),RAD(90),0),CF(.5,.5,1)*CFANG(RAD(-180),RAD(90),0),Sine,S.stanceSettings.Speed)tweenJoint(Root,CF(0,-1,0)*CFANG(RAD(-90),0,RAD(180)),nil,Sine,S.stanceSettings.Speed)tweenJoint(headWeld,CF(0,1.5,0),nil,Sine,S.stanceSettings.Speed)else ABWeld.C0=CF(0,0,-0.0625)LLegWeld.C0=legC0.Crouch[1]RLegWeld.C0=legC0.Crouch[2]s.C0,s.C1=CF(-1,-0.5,0)*CFANG(0,RAD(-90),0),CF(-0.5,.5,1)*CFANG(0,RAD(-90),RAD(-90))N.C0,N.C1=CF(1,-0.5,.25)*CFANG(RAD(-180),RAD(90),0),CF(.5,.5,1)*CFANG(RAD(-180),RAD(90),0)Root.C0=CF(0,-1,0)*CFANG(RAD(-90),0,RAD(180))headWeld.C0=CF(0,1.5,0)end end function Prone()local s=Torso["\076\101\102\116 \072\105\112"]local N=Torso["\082\105\103\104\116 \072\105\112"]s.Part1=nil LLegWeld.Part1=LLeg N.Part1=nil RLegWeld.Part1=RLeg Stance=2 spreadStance="\080\114\111\110\101"baseSpread=S.spreadSettings[spreadZoom][spreadStance][spreadMotion]if S.stanceSettings.Anim then spawn(function()local s=stanceSway local N=0 local g=1.5/S.stanceSettings.Speed while true do RS.RenderStepped:wait()local b=N+g N=b>90 and 90 or b if Stance~=2 then break end stanceSway=numLerp(s,.5,Sine(N))if N==90 then break end end end)tweenJoint(ABWeld,CF(0,0,-0.1),nil,Sine,S.stanceSettings.Speed)tweenJoint(LLegWeld,legC0.Prone[1],nil,Sine,S.stanceSettings.Speed)tweenJoint(RLegWeld,legC0.Prone[2],nil,Sine,S.stanceSettings.Speed)tweenJoint(Root,CF(0,-2.5,1)*CFANG(RAD(180),0,RAD(180)),nil,Sine,S.stanceSettings.Speed)tweenJoint(headWeld,CF(0,1,1)*CFANG(RAD(90),0,0),nil,Sine,S.stanceSettings.Speed)else ABWeld.C0=CF(0,0,-0.125)LLegWeld.C0=legC0.Prone[1]RLegWeld.C0=legC0.Prone[2]Root.C0=CF(0,-2.5,1)*CFANG(RAD(180),0,RAD(180))headWeld.C0=CF(0,1,1)*CFANG(RAD(90),0,0)end end function Dive()onGround=false local s=((HRP.CFrame*CFANG(S.diveSettings.Angle,0,0)).lookVector*S.walkSpeeds.Sprinting)*S.diveSettings.Force local N=Instance.new("\066\111\100\121\070\111\114\099\101")N.force=s+Vector3.new(0,playerMass*196.2,0)N.Parent=HRP delay(.05,function()spawn(function()while true do local s=Ray.new(HRP.Position,V3(0,-3.1,0))local N,g=workspace:FindPartOnRayWithIgnoreList(s,Ignore)if N then onGround=true break end wait()end end)Prone()wait(.1)N:Destroy()end)end
--------------------[ STANCE FUNCTIONS ]----------------------------------------------

function Stand(onDeselected)
	local LHip = Torso["Left Hip"]
	local RHip = Torso["Right Hip"]
	LLegWeld.Part1 = nil
	LHip.Part1 = LLeg
	RLegWeld.Part1 = nil
	RHip.Part1 = RLeg
	Stance = 0
	spreadStance = "Stand"
	baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
	if S.stanceSettings.Anim and not onDeselected then
		spawn(function()
			local prevStanceSway = stanceSway
			local X = 0
			local Increment = 1.5 / S.stanceSettings.Speed
			while true do
				RS.RenderStepped:wait()
				local newX = X + Increment
				X = (newX > 90 and 90 or newX)
				if Stance ~= 0 then
					break
				end
				stanceSway = numLerp(prevStanceSway, 1, Sine(X))
				if X == 90 then
					break
				end
			end
		end)
		tweenJoint(ABWeld, CF(), nil, Sine, S.stanceSettings.Speed)
		tweenJoint(LLegWeld, legC0.Stand[1], nil, Sine, S.stanceSettings.Speed)
		tweenJoint(RLegWeld, legC0.Stand[2], nil, Sine, S.stanceSettings.Speed)
		tweenJoint(
			LHip,
			CF(-1, -1, 0) * CFANG(0, RAD(-90), 0),
			CF(-0.5, 1, 0) * CFANG(0, RAD(-90), 0),
			Sine,
			S.stanceSettings.Speed
		)
		tweenJoint(
			RHip,
			CF(1, -1, 0) * CFANG(RAD(-180), RAD(90), 0),
			CF(0.5, 1, 0) * CFANG(RAD(-180), RAD(90), 0),
			Sine,
			S.stanceSettings.Speed
		)
		tweenJoint(Root, CFANG(RAD(-90), 0, RAD(180)), nil, Sine, S.stanceSettings.Speed)
		tweenJoint(headWeld, CF(0, 1.5, 0), nil, Sine, S.stanceSettings.Speed)
	elseif onDeselected or not S.stanceSettings.Anim then
		ABWeld.C0 = CF()
		LLegWeld.C0 = legC0.Stand[1]
		RLegWeld.C0 = legC0.Stand[2]
		LHip.C0, LHip.C1 = CF(-1, -1, 0) * CFANG(0, RAD(-90), 0), CF(-0.5, 1, 0) * CFANG(0, RAD(-90), 0)
		RHip.C0, RHip.C1 = CF(1, -1, 0) * CFANG(RAD(-180), RAD(90), 0), CF(0.5, 1, 0) * CFANG(RAD(-180), RAD(90), 0)
		Root.C0 = CFANG(RAD(-90), 0, RAD(180))
		headWeld.C0 = CF(0, 1.5, 0)
	end
end

function Crouch()
	local LHip = Torso["Left Hip"]
	local RHip = Torso["Right Hip"]
	LHip.Part1 = nil
	LLegWeld.Part1 = LLeg
	RHip.Part1 = nil
	RLegWeld.Part1 = RLeg
	Stance = 1
	spreadStance = "Crouch"
	baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
	if S.stanceSettings.Anim then
		spawn(function()
			local prevStanceSway = stanceSway
			local X = 0
			local Increment = 1.5 / S.stanceSettings.Speed
			while true do
				RS.RenderStepped:wait()
				local newX = X + Increment
				X = (newX > 90 and 90 or newX)
				if Stance ~= 1 then
					break
				end
				stanceSway = numLerp(prevStanceSway, 0.75, Sine(X))
				if X == 90 then
					break
				end
			end
		end)
		tweenJoint(ABWeld, CF(0, 0, -0.05), nil, Sine, S.stanceSettings.Speed)
		tweenJoint(LLegWeld, legC0.Crouch[1], nil, Sine, S.stanceSettings.Speed)
		tweenJoint(RLegWeld, legC0.Crouch[2], nil, Sine, S.stanceSettings.Speed)
		tweenJoint(
			LHip,
			CF(-1, -0.5, 0) * CFANG(0, RAD(-90), 0),
			CF(-0.5, 0.5, 1) * CFANG(0, RAD(-90), RAD(-90)),
			Sine,
			S.stanceSettings.Speed
		)
		tweenJoint(
			RHip,
			CF(1, -0.5, 0.25) * CFANG(RAD(-180), RAD(90), 0),
			CF(0.5, 0.5, 1) * CFANG(RAD(-180), RAD(90), 0),
			Sine,
			S.stanceSettings.Speed
		)
		tweenJoint(Root, CF(0, -1, 0) * CFANG(RAD(-90), 0, RAD(180)), nil, Sine, S.stanceSettings.Speed)
		tweenJoint(headWeld, CF(0, 1.5, 0), nil, Sine, S.stanceSettings.Speed)
	else
		ABWeld.C0 = CF(0, 0, -1 / 16)
		LLegWeld.C0 = legC0.Crouch[1]
		RLegWeld.C0 = legC0.Crouch[2]
		LHip.C0, LHip.C1 = CF(-1, -0.5, 0) * CFANG(0, RAD(-90), 0), CF(-0.5, 0.5, 1) * CFANG(0, RAD(-90), RAD(-90))
		RHip.C0, RHip.C1 =
			CF(1, -0.5, 0.25) * CFANG(RAD(-180), RAD(90), 0), CF(0.5, 0.5, 1) * CFANG(RAD(-180), RAD(90), 0)
		Root.C0 = CF(0, -1, 0) * CFANG(RAD(-90), 0, RAD(180))
		headWeld.C0 = CF(0, 1.5, 0)
	end
end

function Prone()
	local LHip = Torso["Left Hip"]
	local RHip = Torso["Right Hip"]
	LHip.Part1 = nil
	LLegWeld.Part1 = LLeg
	RHip.Part1 = nil
	RLegWeld.Part1 = RLeg
	Stance = 2
	spreadStance = "Prone"
	baseSpread = S.spreadSettings[spreadZoom][spreadStance][spreadMotion]
	if S.stanceSettings.Anim then
		spawn(function()
			local prevStanceSway = stanceSway
			local X = 0
			local Increment = 1.5 / S.stanceSettings.Speed
			while true do
				RS.RenderStepped:wait()
				local newX = X + Increment
				X = (newX > 90 and 90 or newX)
				if Stance ~= 2 then
					break
				end
				stanceSway = numLerp(prevStanceSway, 0.5, Sine(X))
				if X == 90 then
					break
				end
			end
		end)
		tweenJoint(ABWeld, CF(0, 0, -0.1), nil, Sine, S.stanceSettings.Speed)
		tweenJoint(LLegWeld, legC0.Prone[1], nil, Sine, S.stanceSettings.Speed)
		tweenJoint(RLegWeld, legC0.Prone[2], nil, Sine, S.stanceSettings.Speed)
		tweenJoint(Root, CF(0, -2.5, 1) * CFANG(RAD(180), 0, RAD(180)), nil, Sine, S.stanceSettings.Speed)
		tweenJoint(headWeld, CF(0, 1, 1) * CFANG(RAD(90), 0, 0), nil, Sine, S.stanceSettings.Speed)
	else
		ABWeld.C0 = CF(0, 0, -1 / 8)
		LLegWeld.C0 = legC0.Prone[1]
		RLegWeld.C0 = legC0.Prone[2]
		Root.C0 = CF(0, -2.5, 1) * CFANG(RAD(180), 0, RAD(180))
		headWeld.C0 = CF(0, 1, 1) * CFANG(RAD(90), 0, 0)
	end
end

function Dive()
	onGround = false
	local diveDirection = (HRP.CFrame * CFANG(S.diveSettings.Angle, 0, 0)).lookVector
		* S.walkSpeeds.Sprinting
		* S.diveSettings.Force
	local BF = Instance.new("BodyForce")
	BF.force = diveDirection + Vector3.new(0, playerMass * 196.2, 0)
	BF.Parent = HRP
	--[[spawn(function()
		HRP.Velocity = HRP.CFrame.lookVector * 60 + V3(0, 40, 0)
		wait(0.1)
		HRP.Velocity = HRP.CFrame.lookVector * 70 + V3(0, 30, 0)
		wait(0.4)
		HRP.Velocity = HRP.CFrame.lookVector * 30 + V3(0, -10, 0)
	end)]]
	delay(0.05, function()
		spawn(function()
			while true do
				local newRay = Ray.new(HRP.Position, V3(0, -3.1, 0))
				local H, _ = workspace:FindPartOnRayWithIgnoreList(newRay, Ignore)
				if H then
					onGround = true
					break
				end
				wait()
			end
		end)
		Prone()
		wait(0.1)
		BF:Destroy()
	end)
end
