local s=_Tune.FinalDrive*_Tune.FDMult local u=(s*30)/math.pi local X=(workspace.Gravity*_Tune.InclineComp)/32.2 local x=(wDia*math.pi)/60 local y=CFrame.Angles(math.pi/2,-math.pi/2,0)local t=CFrame.Angles(0,math.pi,0)local W=.70710678118655 if _Tune.Aspiration=="\083\105\110\103\108\101"then _TCount=1 _TPsi=_Tune.Boost elseif _Tune.Aspiration=="\068\111\117\098\108\101"then _TCount=2 _TPsi=_Tune.Boost*2 end local l=_Tune.Horsepower/100 local c=(((_Tune.Horsepower*(_TPsi*(_Tune.CompressRatio/10)))/7.5)/2)/100 local C=_Tune.PeakRPM/1000 local H=_Tune.PeakSharpness local T=_Tune.CurveMult local S=_Tune.EqPoint/1000 function curveHP(s)s=s/1000 return(-(s-C)^2*math.min(l/C^2,T^(C/l))+l)*(s-s^H/(H*C^(H-1)))end local v=curveHP(_Tune.PeakRPM)function curvePSI(s)s=s/1000 return(-(s-C)^2*math.min(c/C^2,T^(C/c))+c)*(s-s^H/(H*C^(H-1)))end local K=curvePSI(_Tune.PeakRPM)function GetCurve(u,X)local x=math.max(curveHP(u)/(v/l),0)*100 return x,((((x*(S/u))*_Tune.Ratios[X+2])*s)*hpScaling)*1000 end function GetPsiCurve(u,X)local x=math.max(curvePSI(u)/(K/c),0)*100 return x,((((x*(S/u))*_Tune.Ratios[X+2])*s)*hpScaling)*1000 end local U={}local D={}for s,u in pairs(_Tune.Ratios)do local X={}local x={}for u=math.floor(_Tune.IdleRPM/100),math.ceil((_Tune.Redline+100)/100),1 do local y={}local t={}y.Horsepower,y.Torque=GetCurve(u*100,s-2)t.Horsepower,t.Torque=GetPsiCurve(u*100,s-2)hp1,tq1=GetCurve((u+1)*100,s-2)hp2,tq2=GetPsiCurve((u+1)*100,s-2)y.HpSlope=hp1-y.Horsepower t.HpSlope=hp2-t.Horsepower y.TqSlope=tq1-y.Torque t.TqSlope=tq2-t.Torque X[u]=y x[u]=t end table.insert(U,X)table.insert(D,x)end wait()function Auto()local X=0 for s,u in pairs(Drive)do if u.RotVelocity.Magnitude>X then X=u.RotVelocity.Magnitude end end if _IsOn then _ClutchOn=true if _CGear.Value>=1 then if _GBrake>0 and car.DriveSeat.Velocity.Magnitude<5 then _CGear.Value=1 else if _Tune.AutoShiftMode=="\082\080\077"then if _RPM>_Tune.PeakRPM+(_Tune.AutoUpThresh*_GThrot+_Tune.IdleRPM)then if _CGear.Value~=0 and _CGear.Value~=#_Tune.Ratios-2 then _GThrotShift=0 wait(_Tune.ShiftTime)_GThrotShift=1 end _CGear.Value=math.min(_CGear.Value+1,#_Tune.Ratios-2)elseif math.max(math.min((X*_Tune.Ratios[_CGear.Value+1])*u,_Tune.Redline+100),_Tune.IdleRPM)<_Tune.PeakRPM-(_Tune.AutoDownThresh*_GThrot+_Tune.IdleRPM)then if _CGear.Value~=1 then _GThrotShift=0 wait(_Tune.ShiftTime/2)_GThrotShift=1 end _CGear.Value=math.max(_CGear.Value-1,1)end else if car.DriveSeat.Velocity.Magnitude>math.ceil(((x*(_Tune.PeakRPM+(_Tune.AutoUpThresh*(1-_GThrot/3)+_Tune.IdleRPM)))/_Tune.Ratios[_CGear.Value+2])/s)then if _CGear.Value~=0 and _CGear.Value~=#_Tune.Ratios-2 then _GThrotShift=0 wait(_Tune.ShiftTime)_GThrotShift=1 end _CGear.Value=math.min(_CGear.Value+1,#_Tune.Ratios-2)elseif car.DriveSeat.Velocity.Magnitude<math.ceil(((x*(_Tune.PeakRPM-(_Tune.AutoDownThresh*(1-_GThrot/3)+_Tune.IdleRPM)))/_Tune.Ratios[_CGear.Value+1])/s)then if _CGear.Value~=1 then _GThrotShift=0 wait(_Tune.ShiftTime/2)_GThrotShift=1 end _CGear.Value=math.max(_CGear.Value-1,1)end end end end end end local Z=1 function Engine()if _CGear.Value==0 then _ClutchOn=false else _ClutchOn=true end local s=_Tune.IdleRPM if not _IsOn then s=0 _CGear.Value=0 _ClutchOn=false _GThrot=_Tune.IdleThrottle/100 end if car.DriveSeat.Tic.Value then s=0 _GThrot=_Tune.IdleThrottle/100 end local x=0 local l=0 for s,u in pairs(Drive)do x=x+u.RotVelocity.Magnitude l=l+1 end x=x/l if _ClutchOn then local X=math.max(math.min((x*_Tune.Ratios[_CGear.Value+2])*u,_Tune.Redline+100),s)local y=math.min(math.abs(X-_RPM)/_Tune.ClutchTol,.9)_RPM=_RPM*y+X*(1-y)else if _GThrot-_Tune.IdleThrottle/100>0 then if _RPM>_Tune.Redline then _RPM=_RPM-_Tune.RevBounce*2 else _RPM=math.min(_RPM+_Tune.RevAccel*_GThrot,_Tune.Redline+100)end else _RPM=math.max(_RPM-_Tune.RevDecay,s)end end _spLimit=(_Tune.Redline+100)/(u*_Tune.Ratios[_CGear.Value+2])if _RPM>_Tune.Redline then if _CGear.Value<#_Tune.Ratios-2 then _RPM=_RPM-_Tune.RevBounce else _RPM=_RPM-_Tune.RevBounce*.5 end end local c=_TPsi/_TCount _Boost=_Boost+(((((_HP*(_GThrot*1.2))/_Tune.Horsepower)/8-(_Boost/c)*(c/15))*((36/_Tune.TurboSize)*2))/c)*15 if _Boost<.05 then _Boost=.05 elseif _Boost>2 then _Boost=2 end local C=U[_CGear.Value+2][math.floor(math.min(_Tune.Redline,math.max(_Tune.IdleRPM,_RPM))/100)]_NH=C.Horsepower+(C.HpSlope*((_RPM-math.floor(_RPM/100))/1000))%1 _NT=C.Torque+(C.TqSlope*((_RPM-math.floor(_RPM/100))/1000))%1 if car.DriveSeat.Velocity.Magnitude*.56818181818182>car.DriveSeat.CCS.Value+.5 and car.DriveSeat.CC.Value==true then _HP,_OutTorque=0,0 else if _Tune.Aspiration~="\078\097\116\117\114\097\108"then local s=D[_CGear.Value+2][math.floor(math.min(_Tune.Redline,math.max(_Tune.IdleRPM,_RPM))/100)]_BH=s.Horsepower+(s.HpSlope*((_RPM-math.floor(_RPM/100))/1000))%1 _BT=s.Torque+(s.TqSlope*((_RPM-math.floor(_RPM/100))/1000))%1 _HP=_NH+_BH*(_Boost/2)_OutTorque=_NT+_BT*(_Boost/2)else _HP=_NH _OutTorque=_NT end end local H=car.DriveSeat.CFrame.lookVector.y*X if _CGear.Value==-1 then H=-H end _OutTorque=_OutTorque*math.max(1,1+H)local T=0 local S=0 local v=0 local K=0 for s,u in pairs(car.Wheels:GetChildren())do if u.Name=="\070\076"or u.Name=="\070\082"or u.Name=="\070"then T=T+u.RotVelocity.Magnitude S=S+1 elseif u.Name=="\082\076"or u.Name=="\082\082"or u.Name=="\082"then v=v+u.RotVelocity.Magnitude K=K+1 end end T=T/S v=v/K local i=(T+v)/2 for s,u in pairs(car.Wheels:GetChildren())do local X=(CFrame.new(u.Position-(u.Arm.CFrame*y).lookVector,u.Position)*t).lookVector local x=1 local l=1 if u.Name=="\070\076"or u.Name=="\082\076"then x=-1 end if car.DriveSeat.AWD.Value then _OutTorque=_OutTorque*W end if u.Name=="\070\076"or u.Name=="\070\082"then l=math.max(0,math.min(1,1+(((u.RotVelocity.Magnitude-T)/T)/(math.max(_Tune.FDiffSlipThres,1)/100))*((_Tune.FDiffLockThres-50)/50)))if _Tune.Config=="\065\087\068"then l=math.max(0,math.min(1,l*(1+(((T-i)/i)/(math.max(_Tune.CDiffSlipThres,1)/100))*((_Tune.CDiffLockThres-50)/50))))end elseif u.Name=="\082\076"or u.Name=="\082\082"then l=math.max(0,math.min(1,1+(((u.RotVelocity.Magnitude-v)/v)/(math.max(_Tune.RDiffSlipThres,1)/100))*((_Tune.RDiffLockThres-50)/50)))if car.DriveSeat.AWD.Value then l=math.max(0,math.min(1,l*(1+(((v-i)/i)/(math.max(_Tune.CDiffSlipThres,1)/100))*((_Tune.CDiffLockThres-50)/50))))end end _TCSActive=false _ABSActive=false if _PBrake.Value and(u.Name=="\082\082"or u.Name=="\082\076")then u["\035\065\086"].maxTorque=Vector3.new(math.abs(X.x),math.abs(X.y),math.abs(X.z))*PBrakeForce u["\035\065\086"].angularvelocity=Vector3.new()else if _GBrake==0 then local s=false for X,x in pairs(Drive)do if x==u then s=true end end if s then local s=1 if not car.DriveSeat.IsOn.Value then s=0 end local y=1 if not _ClutchOn then y=0 end local t=math.min(_GThrot+_CThrot,1)*_GThrotShift Z=1 if _TCS then Z=1-math.min(math.max(0,math.abs(u.RotVelocity.Magnitude*(u.Size.x/2)-u.Velocity.Magnitude)-_Tune.TCSThreshold)/_Tune.TCSGradient,1)*(1-_Tune.TCSLimit/100)end if Z<1 then _TCSAmt=Z _TCSActive=true end local W=1 if _CGear.Value==-1 then W=-1 end u["\035\065\086"].maxTorque=((((((Vector3.new(math.abs(X.x),math.abs(X.y),math.abs(X.z))*_OutTorque)*(1+(u.RotVelocity.Magnitude/60)^1.15))*t)*Z)*l)*s)*y u["\035\065\086"].angularvelocity=((X*x)*_spLimit)*W else u["\035\065\086"].maxTorque=Vector3.new()u["\035\065\086"].angularvelocity=Vector3.new()end else local s=_GBrake+_CBrake local x=1 if _ABS and math.abs(u.RotVelocity.Magnitude*(u.Size.x/2)-u.Velocity.Magnitude)-_Tune.ABSThreshold>0 then x=0 end _ABSActive=x<1 if u.Name=="\070\076"or u.Name=="\070\082"or u.Name=="\070"then u["\035\065\086"].maxTorque=((Vector3.new(math.abs(X.x),math.abs(X.y),math.abs(X.z))*FBrakeForce)*s)*x else u["\035\065\086"].maxTorque=((Vector3.new(math.abs(X.x),math.abs(X.y),math.abs(X.z))*RBrakeForce)*s)*x end u["\035\065\086"].angularvelocity=Vector3.new()end end end end


	local fFD = _Tune.FinalDrive*_Tune.FDMult
	local fFDr = fFD*30/math.pi
	local cGrav = workspace.Gravity*_Tune.InclineComp/32.2
	local wDRatio = wDia*math.pi/60
	local cfWRot = CFrame.Angles(math.pi/2,-math.pi/2,0)
	local cfYRot = CFrame.Angles(0,math.pi,0)
	local rtTwo = (2^.5)/2
	
	if _Tune.Aspiration == "Single" then
		_TCount = 1
		_TPsi = _Tune.Boost
	elseif _Tune.Aspiration == "Double" then
		_TCount = 2
		_TPsi = _Tune.Boost*2
	end

	--Horsepower Curve
	
	
	local HP=_Tune.Horsepower/100
	local HP_B=((_Tune.Horsepower*((_TPsi)*(_Tune.CompressRatio/10))/7.5)/2)/100
	local Peak=_Tune.PeakRPM/1000
	local Sharpness=_Tune.PeakSharpness
	local CurveMult=_Tune.CurveMult
	local EQ=_Tune.EqPoint/1000
	
	--Horsepower Curve
	
	function curveHP(RPM)
		RPM=RPM/1000
		return ((-(RPM-Peak)^2)*math.min(HP/(Peak^2),CurveMult^(Peak/HP))+HP)*(RPM-((RPM^Sharpness)/(Sharpness*Peak^(Sharpness-1))))
	end
	
	local PeakCurveHP = curveHP(_Tune.PeakRPM)
	
	function curvePSI(RPM)
		RPM=RPM/1000
		return ((-(RPM-Peak)^2)*math.min(HP_B/(Peak^2),CurveMult^(Peak/HP_B))+HP_B)*(RPM-((RPM^Sharpness)/(Sharpness*Peak^(Sharpness-1))))
	end
	local PeakCurvePSI = curvePSI(_Tune.PeakRPM)
	
	--Plot Current Horsepower
	function GetCurve(x,gear)
		local hp=(math.max(curveHP(x)/(PeakCurveHP/HP),0))*100
		return hp,((hp*(EQ/x))*_Tune.Ratios[gear+2]*fFD*hpScaling)*1000
	end
	
	--Plot Current Boost (addition to Horsepower)
	function GetPsiCurve(x,gear)
		local hp=(math.max(curvePSI(x)/(PeakCurvePSI/HP_B),0))*100
		return hp,((hp*(EQ/x))*_Tune.Ratios[gear+2]*fFD*hpScaling)*1000
	end	
	
	--Output Cache	
	local HPCache = {}
	local PSICache = {}
	
	for gear,ratio in pairs(_Tune.Ratios) do
		local nhpPlot = {}
		local bhpPlot = {}
		for rpm = math.floor(_Tune.IdleRPM/100),math.ceil((_Tune.Redline+100)/100) do
			local ntqPlot = {}
			local btqPlot = {}
			ntqPlot.Horsepower,ntqPlot.Torque = GetCurve(rpm*100,gear-2)
			btqPlot.Horsepower,btqPlot.Torque = GetPsiCurve(rpm*100,gear-2)
			hp1,tq1 = GetCurve((rpm+1)*100,gear-2)
			hp2,tq2 = GetPsiCurve((rpm+1)*100,gear-2)
			ntqPlot.HpSlope = (hp1 - ntqPlot.Horsepower)
			btqPlot.HpSlope = (hp2 - btqPlot.Horsepower)
			ntqPlot.TqSlope = (tq1 - ntqPlot.Torque)
			btqPlot.TqSlope = (tq2 - btqPlot.Torque)
			nhpPlot[rpm] = ntqPlot
			bhpPlot[rpm] = btqPlot
		end
		table.insert(HPCache,nhpPlot)
		table.insert(PSICache,bhpPlot)
	end

	--Powertrain
	wait()

	--Automatic Transmission
	function Auto()
		local maxSpin=0
		for i,v in pairs(Drive) do if v.RotVelocity.Magnitude>maxSpin then maxSpin = v.RotVelocity.Magnitude end end
		if _IsOn then
			_ClutchOn = true
			if _CGear.Value >= 1 then
				if _GBrake > 0  and car.DriveSeat.Velocity.Magnitude < 5 then
					_CGear.Value = 1
				else
					if _Tune.AutoShiftMode == "RPM" then
						if _RPM>(_Tune.PeakRPM+((_Tune.AutoUpThresh*_GThrot)+_Tune.IdleRPM)) then
							if (_CGear.Value ~= 0) and (_CGear.Value ~= #_Tune.Ratios-2) then
								_GThrotShift = 0
								wait(_Tune.ShiftTime)
								_GThrotShift = 1
							end
							_CGear.Value=math.min(_CGear.Value+1,#_Tune.Ratios-2) 
						elseif math.max(math.min(maxSpin*_Tune.Ratios[_CGear.Value+1]*fFDr,_Tune.Redline+100),_Tune.IdleRPM)<(_Tune.PeakRPM-((_Tune.AutoDownThresh*_GThrot)+_Tune.IdleRPM)) then
							if _CGear.Value ~= 1 then
								_GThrotShift = 0
								wait(_Tune.ShiftTime/2)
								_GThrotShift = 1
							end
							_CGear.Value=math.max(_CGear.Value-1,1)
						end
					else
						if car.DriveSeat.Velocity.Magnitude > math.ceil(wDRatio*(_Tune.PeakRPM+((_Tune.AutoUpThresh*(1-(_GThrot/3)))+_Tune.IdleRPM))/_Tune.Ratios[_CGear.Value+2]/fFD) then
							if (_CGear.Value ~= 0) and (_CGear.Value ~= #_Tune.Ratios-2) then
								_GThrotShift = 0
								wait(_Tune.ShiftTime)
								_GThrotShift = 1
							end
							_CGear.Value=math.min(_CGear.Value+1,#_Tune.Ratios-2)
						elseif car.DriveSeat.Velocity.Magnitude < math.ceil(wDRatio*(_Tune.PeakRPM-((_Tune.AutoDownThresh*(1-(_GThrot/3)))+_Tune.IdleRPM))/_Tune.Ratios[_CGear.Value+1]/fFD) then
							if _CGear.Value ~= 1 then
								_GThrotShift = 0
								wait(_Tune.ShiftTime/2)
								_GThrotShift = 1
							end
							_CGear.Value=math.max(_CGear.Value-1,1)
						end
					end
				end
			end
		end 
	end
	
	local tqTCS = 1
	--Apply Power
	function Engine()
		--Neutral Gear
		if _CGear.Value==0 then _ClutchOn = false else _ClutchOn = true end
	
		--Car Is Off
		local revMin = _Tune.IdleRPM
		if not _IsOn then 
			revMin = 0 
			_CGear.Value = 0
			_ClutchOn = false
			_GThrot = _Tune.IdleThrottle/100
		end
		if car.DriveSeat.Tic.Value then
			revMin = 0 
			_GThrot = _Tune.IdleThrottle/100
		end
		
		--Determine RPM
		local maxSpin=0
		local maxCount=0
		for i,v in pairs(Drive) do maxSpin = maxSpin + v.RotVelocity.Magnitude maxCount = maxCount + 1 end
		maxSpin=maxSpin/maxCount
		
		if _ClutchOn then
			local aRPM = math.max(math.min(maxSpin*_Tune.Ratios[_CGear.Value+2]*fFDr,_Tune.Redline+100),revMin)
			local clutchP = math.min(math.abs(aRPM-_RPM)/_Tune.ClutchTol,.9)
			_RPM = _RPM*clutchP  +  aRPM*(1-clutchP)
		else
			if _GThrot-(_Tune.IdleThrottle/100)>0 then
				if _RPM>_Tune.Redline then
					_RPM = _RPM-_Tune.RevBounce*2
				else
					_RPM = math.min(_RPM+_Tune.RevAccel*_GThrot,_Tune.Redline+100)
				end
			else
				_RPM = math.max(_RPM-_Tune.RevDecay,revMin)
			end
		end
		
		--Rev Limiter
		_spLimit = (_Tune.Redline+100)/(fFDr*_Tune.Ratios[_CGear.Value+2])
		if _RPM>_Tune.Redline then 
			if _CGear.Value<#_Tune.Ratios-2 then
				_RPM = _RPM-_Tune.RevBounce
			else
				_RPM = _RPM-_Tune.RevBounce*.5
			end
		end
		
		local TPsi = _TPsi/_TCount
		_Boost = _Boost + ((((((_HP*(_GThrot*1.2)/_Tune.Horsepower)/8)-(((_Boost/TPsi*(TPsi/15)))))*((36/_Tune.TurboSize)*2))/TPsi)*15)
		if _Boost < 0.05 then _Boost = 0.05 elseif _Boost > 2 then _Boost = 2 end
		
		local cTq = HPCache[_CGear.Value+2][math.floor(math.min(_Tune.Redline,math.max(_Tune.IdleRPM,_RPM))/100)]
		_NH = cTq.Horsepower+(cTq.HpSlope*((_RPM-math.floor(_RPM/100))/1000)%1)
		_NT = cTq.Torque+(cTq.TqSlope*((_RPM-math.floor(_RPM/100))/1000)%1)
			if ((car.DriveSeat.Velocity.Magnitude*((10/12) * (60/88))) > car.DriveSeat.CCS.Value+0.5) and (car.DriveSeat.CC.Value == true) then
				_HP,_OutTorque = 0,0
			else
				if _Tune.Aspiration ~= "Natural" then
					local bTq = PSICache[_CGear.Value+2][math.floor(math.min(_Tune.Redline,math.max(_Tune.IdleRPM,_RPM))/100)]
					_BH = bTq.Horsepower+(bTq.HpSlope*((_RPM-math.floor(_RPM/100))/1000)%1)
					_BT = bTq.Torque+(bTq.TqSlope*((_RPM-math.floor(_RPM/100))/1000)%1)
					_HP = _NH + (_BH*(_Boost/2))
					_OutTorque = _NT + (_BT*(_Boost/2))
				else
					_HP = _NH
					_OutTorque = _NT
				end
			end
		
		local iComp =(car.DriveSeat.CFrame.lookVector.y)*cGrav
		if _CGear.Value==-1 then iComp=-iComp end
		_OutTorque = _OutTorque*math.max(1,(1+iComp))
		
		--Average Rotational Speed Calculation
		local fwspeed=0
		local fwcount=0
		local rwspeed=0
		local rwcount=0
		
		for i,v in pairs(car.Wheels:GetChildren()) do
			if v.Name=="FL" or v.Name=="FR" or v.Name == "F" then
				fwspeed=fwspeed+v.RotVelocity.Magnitude
				fwcount=fwcount+1
			elseif v.Name=="RL" or v.Name=="RR" or v.Name == "R" then
				rwspeed=rwspeed+v.RotVelocity.Magnitude
				rwcount=rwcount+1
			end
		end
		fwspeed=fwspeed/fwcount
		rwspeed=rwspeed/rwcount	
		local cwspeed=(fwspeed+rwspeed)/2
		
		--Update Wheels
		for i,v in pairs(car.Wheels:GetChildren()) do
			--Reference Wheel Orientation
			local Ref=(CFrame.new(v.Position-((v.Arm.CFrame*cfWRot).lookVector),v.Position)*cfYRot).lookVector
			local aRef=1
			local diffMult=1
			if v.Name=="FL" or v.Name=="RL" then aRef=-1 end
			
			--AWD Torque Scaling
			if car.DriveSeat.AWD.Value then _OutTorque = _OutTorque*rtTwo end
			
			--Differential/Torque-Vectoring
			if v.Name=="FL" or v.Name=="FR" then
				diffMult=math.max(0,math.min(1,1+((((v.RotVelocity.Magnitude-fwspeed)/fwspeed)/(math.max(_Tune.FDiffSlipThres,1)/100))*((_Tune.FDiffLockThres-50)/50))))
				if _Tune.Config == "AWD" then
					diffMult=math.max(0,math.min(1,diffMult*(1+((((fwspeed-cwspeed)/cwspeed)/(math.max(_Tune.CDiffSlipThres,1)/100))*((_Tune.CDiffLockThres-50)/50)))))
				end
			elseif v.Name=="RL" or v.Name=="RR" then
				diffMult=math.max(0,math.min(1,1+((((v.RotVelocity.Magnitude-rwspeed)/rwspeed)/(math.max(_Tune.RDiffSlipThres,1)/100))*((_Tune.RDiffLockThres-50)/50))))
				if car.DriveSeat.AWD.Value then
					diffMult=math.max(0,math.min(1,diffMult*(1+((((rwspeed-cwspeed)/cwspeed)/(math.max(_Tune.CDiffSlipThres,1)/100))*((_Tune.CDiffLockThres-50)/50)))))
				end
			end
			
			_TCSActive = false
			_ABSActive = false
			--Output
			if _PBrake.Value and (v.Name=="RR" or v.Name=="RL") then
				--PBrake
				v["#AV"].maxTorque=Vector3.new(math.abs(Ref.x),math.abs(Ref.y),math.abs(Ref.z))*PBrakeForce
				v["#AV"].angularvelocity=Vector3.new()
			else
				--Apply Power
				if _GBrake==0 then
					local driven = false
					for _,a in pairs(Drive) do if a==v then driven = true end end
					if driven then
						local on=1
						if not car.DriveSeat.IsOn.Value then on=0 end
						local clutch=1
						if not _ClutchOn then clutch=0 end
						local throt = (math.min(_GThrot +_CThrot,1)) * _GThrotShift
						
						--Apply TCS
						tqTCS = 1
						if _TCS then
							tqTCS = 1-(math.min(math.max(0,math.abs(v.RotVelocity.Magnitude*(v.Size.x/2) - v.Velocity.Magnitude)-_Tune.TCSThreshold)/_Tune.TCSGradient,1)*(1-(_Tune.TCSLimit/100)))
						end
						if tqTCS < 1 then
							_TCSAmt = tqTCS
							_TCSActive = true
						end
						
						--Update Forces
						local dir=1
						if _CGear.Value==-1 then dir = -1 end
						v["#AV"].maxTorque=Vector3.new(math.abs(Ref.x),math.abs(Ref.y),math.abs(Ref.z))*_OutTorque*(1+(v.RotVelocity.Magnitude/60)^1.15)*throt*tqTCS*diffMult*on*clutch
						v["#AV"].angularvelocity=Ref*aRef*_spLimit*dir
					else
						v["#AV"].maxTorque=Vector3.new()
						v["#AV"].angularvelocity=Vector3.new()
					end
					
				--Brakes
				else
					local brake = (_GBrake + _CBrake)
					
					--Apply ABS
					local tqABS = 1
					if _ABS and math.abs(v.RotVelocity.Magnitude*(v.Size.x/2) - v.Velocity.Magnitude)-_Tune.ABSThreshold>0 then
						tqABS = 0
					end
					_ABSActive = (tqABS<1)
					
					--Update Forces
					if v.Name=="FL" or v.Name=="FR" or v.Name=="F" then
						v["#AV"].maxTorque=Vector3.new(math.abs(Ref.x),math.abs(Ref.y),math.abs(Ref.z))*FBrakeForce*brake*tqABS
					else
						v["#AV"].maxTorque=Vector3.new(math.abs(Ref.x),math.abs(Ref.y),math.abs(Ref.z))*RBrakeForce*brake*tqABS
					end
					v["#AV"].angularvelocity=Vector3.new()
				end
			end
		end
	end
	
	
	