local U=_Tune.FinalDrive*_Tune.FDMult local f=(U*30)/math.pi local j=(workspace.Gravity*_Tune.InclineComp)/32.2 local M=(wDia*math.pi)/60 local n=CFrame.Angles(math.pi/2,-math.pi/2,0)local o=CFrame.Angles(0,math.pi,0)if _Tune.Aspiration=="\083\105\110\103\108\101"or _Tune.Aspiration=="\083\117\112\101\114"then _TCount=1 _TPsi=_Tune.Boost elseif _Tune.Aspiration=="\068\111\117\098\108\101"then _TCount=2 _TPsi=_Tune.Boost*2 end local H=_Tune.Horsepower/100 local y=(((_Tune.Horsepower*(_TPsi*(_Tune.CompressRatio/10)))/7.5)/2)/100 local V=_Tune.PeakRPM/1000 local u=_Tune.PeakSharpness local W=_Tune.CurveMult local l=_Tune.EqPoint/1000 function curveHP(U)U=U/1000 return(-(U-V)^2*math.min(H/V^2,W^(V/H))+H)*(U-U^u/(u*V^(u-1)))end local i=curveHP(_Tune.PeakRPM)function curvePSI(U)U=U/1000 return(-(U-V)^2*math.min(y/V^2,W^(V/y))+y)*(U-U^u/(u*V^(u-1)))end local b=curvePSI(_Tune.PeakRPM)function GetCurve(f,j)local M=math.max(curveHP(f)/(i/H),0)*100 return M,((((M*(l/f))*_Tune.Ratios[j+2])*U)*hpScaling)*1000 end function GetPsiCurve(f,j)local M=math.max(curvePSI(f)/(b/y),0)*100 return M,((((M*(l/f))*_Tune.Ratios[j+2])*U)*hpScaling)*1000 end local N={}local m={}for U,f in pairs(_Tune.Ratios)do local j={}local M={}for f=math.floor(_Tune.IdleRPM/100),math.ceil((_Tune.Redline+100)/100),1 do local n={}local o={}n.Horsepower,n.Torque=GetCurve(f*100,U-2)o.Horsepower,o.Torque=GetPsiCurve(f*100,U-2)hp1,tq1=GetCurve((f+1)*100,U-2)hp2,tq2=GetPsiCurve((f+1)*100,U-2)n.HpSlope=hp1-n.Horsepower o.HpSlope=hp2-o.Horsepower n.TqSlope=tq1-n.Torque o.TqSlope=tq2-o.Torque j[f]=n M[f]=o end table.insert(N,j)table.insert(m,M)end wait()function Auto()local j=0 for U,f in pairs(Drive)do if f.RotVelocity.Magnitude>j then j=f.RotVelocity.Magnitude end end if _IsOn then _ClutchOn=true if _CGear>=1 then if _GBrake>0 and car.DriveSeat.Velocity.Magnitude<5 then _CGear=1 else if _Tune.AutoShiftMode=="\082\080\077"then if _RPM>_Tune.PeakRPM+_Tune.AutoUpThresh then if _CGear~=0 and _CGear~=#_Tune.Ratios-2 then _GThrotShift=0 wait(_Tune.ShiftTime)_GThrotShift=1 end _CGear=math.min(_CGear+1,#_Tune.Ratios-2)elseif math.max(math.min((j*_Tune.Ratios[_CGear+1])*f,_Tune.Redline+100),_Tune.IdleRPM)<_Tune.PeakRPM-_Tune.AutoDownThresh then if _CGear~=1 then _GThrotShift=0 wait(_Tune.ShiftTime/2)_GThrotShift=1 end _CGear=math.max(_CGear-1,1)end else if car.DriveSeat.Velocity.Magnitude>math.ceil(((M*(_Tune.PeakRPM+_Tune.AutoUpThresh))/_Tune.Ratios[_CGear+2])/U)then if _CGear~=0 and _CGear~=#_Tune.Ratios-2 then _GThrotShift=0 wait(_Tune.ShiftTime)_GThrotShift=1 end _CGear=math.min(_CGear+1,#_Tune.Ratios-2)elseif car.DriveSeat.Velocity.Magnitude<math.ceil(((M*(_Tune.PeakRPM-_Tune.AutoDownThresh))/_Tune.Ratios[_CGear+1])/U)then if _CGear~=1 then _GThrotShift=0 wait(_Tune.ShiftTime/2)_GThrotShift=1 end _CGear=math.max(_CGear-1,1)end end end end end end local F=1 local t=0 function Engine()if _CGear==0 then _ClutchOn=false end local U=_Tune.IdleRPM if not _IsOn then U=0 _CGear=0 _ClutchOn=false _GThrot=_Tune.IdleThrottle/100 end local M=0 local H=0 for U,f in pairs(Drive)do M=M+f.RotVelocity.Magnitude H=H+1 end M=M/H if _ClutchOn then local j=math.max(math.min((M*_Tune.Ratios[_CGear+2])*f,_Tune.Redline+100),U)local n=math.min(math.abs(j-_RPM)/_Tune.ClutchTol,.9)_RPM=_RPM*n+j*(1-n)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,U)end end _spLimit=(_Tune.Redline+100)/(f*_Tune.Ratios[_CGear+2])if _RPM>_Tune.Redline then if _CGear<#_Tune.Ratios-2 then _RPM=_RPM-_Tune.RevBounce else _RPM=_RPM-_Tune.RevBounce*.5 end end local y=_TPsi/_TCount if _Tune.Aspiration~="\083\117\112\101\114"then _Boost=_Boost+(((((_HP*(_GThrot*1.2))/_Tune.Horsepower)/8-(_Boost/y)*(y/15))*((8/_Tune.TurboSize)*2))/y)*15 if _Boost<.05 then _Boost=.05 elseif _Boost>2 then _Boost=2 end else if _GThrot>t then t=math.min(_GThrot,t+_Tune.Sensitivity)elseif _GThrot<t then t=math.max(_GThrot,t-_Tune.Sensitivity)end _Boost=(_RPM/_Tune.Redline)*(.5+1.5*t)end local V=N[_CGear+2][math.floor(math.min(_Tune.Redline,math.max(_Tune.IdleRPM,_RPM))/100)]_NH=V.Horsepower+(V.HpSlope*((_RPM-math.floor(_RPM/100))/1000))%1 _NT=V.Torque+(V.TqSlope*((_RPM-math.floor(_RPM/100))/1000))%1 if _Tune.Aspiration~="\078\097\116\117\114\097\108"then local U=m[_CGear+2][math.floor(math.min(_Tune.Redline,math.max(_Tune.IdleRPM,_RPM))/100)]_BH=U.Horsepower+(U.HpSlope*((_RPM-math.floor(_RPM/100))/1000))%1 _BT=U.Torque+(U.TqSlope*((_RPM-math.floor(_RPM/100))/1000))%1 _HP=_NH+_BH*(_Boost/2)_OutTorque=_NT+_BT*(_Boost/2)else _HP=_NH _OutTorque=_NT end local u=car.DriveSeat.CFrame.lookVector.y*j if _CGear==-1 then u=-u end _OutTorque=_OutTorque*math.max(1,1+u)local W=0 local l=0 local i=0 local b=0 for U,f in pairs(car.Wheels:GetChildren())do if f.Name=="\070\076"or f.Name=="\070\082"or f.Name=="\070"then W=W+f.RotVelocity.Magnitude l=l+1 elseif f.Name=="\082\076"or f.Name=="\082\082"or f.Name=="\082"then i=i+f.RotVelocity.Magnitude b=b+1 end end W=W/l i=i/b local p=(W+i)/2 for U,f in pairs(car.Wheels:GetChildren())do local j=(CFrame.new(f.Position-(f.Arm.CFrame*n).lookVector,f.Position)*o).lookVector local M=1 local H=1 if f.Name=="\070\076"or f.Name=="\082\076"then M=-1 end if f.Name=="\070\076"or f.Name=="\070\082"then H=math.max(0,math.min(1,1+(((f.RotVelocity.Magnitude-W)/W)/(math.max(_Tune.FDiffSlipThres,1)/100))*((_Tune.FDiffLockThres-50)/50)))if _Tune.Config=="\065\087\068"then H=math.max(0,math.min(1,H*(1+(((W-p)/p)/(math.max(_Tune.CDiffSlipThres,1)/100))*((_Tune.CDiffLockThres-50)/50))))end elseif f.Name=="\082\076"or f.Name=="\082\082"then H=math.max(0,math.min(1,1+(((f.RotVelocity.Magnitude-i)/i)/(math.max(_Tune.RDiffSlipThres,1)/100))*((_Tune.RDiffLockThres-50)/50)))if _Tune.Config=="\065\087\068"then H=math.max(0,math.min(1,H*(1+(((i-p)/p)/(math.max(_Tune.CDiffSlipThres,1)/100))*((_Tune.CDiffLockThres-50)/50))))end end _TCSActive=false _ABSActive=false if _PBrake and(f.Name=="\082\082"or f.Name=="\082\076")then f["\035\065\086"].maxTorque=Vector3.new(math.abs(j.x),math.abs(j.y),math.abs(j.z))*PBrakeForce f["\035\065\086"].angularvelocity=Vector3.new()else if _GBrake==0 then local U=false for j,M in pairs(Drive)do if M==f then U=true end end if U then local U=1 if not script.Parent.IsOn.Value then U=0 end local n=1 if not _ClutchOn then n=0 end local o=_GThrot*_GThrotShift local y=_OutTorque if _Tune.Config=="\065\087\068"then local U=(_Tune.TorqueVector+1)/2 if f.Name=="\070\076"or f.Name=="\070\082"then y=y*(1-U)elseif f.Name=="\082\076"or f.Name=="\082\082"then y=y*U end end F=1 if _TCS then F=1-math.min(math.max(0,math.abs(f.RotVelocity.Magnitude*(f.Size.x/2)-f.Velocity.Magnitude)-_Tune.TCSThreshold)/_Tune.TCSGradient,1)*(1-_Tune.TCSLimit/100)end if F<1 then _TCSAmt=F _TCSActive=true end local V=1 if _CGear==-1 then V=-1 end f["\035\065\086"].maxTorque=((((((Vector3.new(math.abs(j.x),math.abs(j.y),math.abs(j.z))*y)*(1+(f.RotVelocity.Magnitude/60)^1.15))*o)*F)*H)*U)*n f["\035\065\086"].angularvelocity=((j*M)*_spLimit)*V else f["\035\065\086"].maxTorque=Vector3.new()f["\035\065\086"].angularvelocity=Vector3.new()end else local U=_GBrake local M=1 if _ABS and math.abs(f.RotVelocity.Magnitude*(f.Size.x/2)-f.Velocity.Magnitude)-_Tune.ABSThreshold>0 then M=0 end _ABSActive=M<1 if f.Name=="\070\076"or f.Name=="\070\082"or f.Name=="\070"then f["\035\065\086"].maxTorque=((Vector3.new(math.abs(j.x),math.abs(j.y),math.abs(j.z))*FBrakeForce)*U)*M else f["\035\065\086"].maxTorque=((Vector3.new(math.abs(j.x),math.abs(j.y),math.abs(j.z))*RBrakeForce)*U)*M end f["\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)
	
	if _Tune.Aspiration == "Single" or _Tune.Aspiration == "Super" 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 >= 1 then
				if _GBrake > 0  and car.DriveSeat.Velocity.Magnitude < 5 then
					_CGear = 1
				else
					if _Tune.AutoShiftMode == "RPM" then
						if _RPM>(_Tune.PeakRPM+_Tune.AutoUpThresh) then
							if (_CGear ~= 0) and (_CGear ~= #_Tune.Ratios-2) then
								_GThrotShift = 0
								wait(_Tune.ShiftTime)
								_GThrotShift = 1
							end
							_CGear=math.min(_CGear+1,#_Tune.Ratios-2) 
						elseif math.max(math.min(maxSpin*_Tune.Ratios[_CGear+1]*fFDr,_Tune.Redline+100),_Tune.IdleRPM)<(_Tune.PeakRPM-_Tune.AutoDownThresh) then
							if _CGear ~= 1 then
								_GThrotShift = 0
								wait(_Tune.ShiftTime/2)
								_GThrotShift = 1
							end
							_CGear=math.max(_CGear-1,1)
						end
					else
						if car.DriveSeat.Velocity.Magnitude > math.ceil(wDRatio*(_Tune.PeakRPM+_Tune.AutoUpThresh)/_Tune.Ratios[_CGear+2]/fFD) then
							if (_CGear ~= 0) and (_CGear ~= #_Tune.Ratios-2) then
								_GThrotShift = 0
								wait(_Tune.ShiftTime)
								_GThrotShift = 1
							end
							_CGear=math.min(_CGear+1,#_Tune.Ratios-2)
						elseif car.DriveSeat.Velocity.Magnitude < math.ceil(wDRatio*(_Tune.PeakRPM-_Tune.AutoDownThresh)/_Tune.Ratios[_CGear+1]/fFD) then
							if _CGear ~= 1 then
								_GThrotShift = 0
								wait(_Tune.ShiftTime/2)
								_GThrotShift = 1
							end
							_CGear=math.max(_CGear-1,1)
						end
					end
				end
			end
		end 
	end
	
	local tqTCS = 1
	local sthrot = 0
	--Apply Power
	function Engine()
		--Neutral Gear
		if _CGear==0 then _ClutchOn = false end
	
		--Car Is Off
		local revMin = _Tune.IdleRPM
		if not _IsOn then 
			revMin = 0 
			_CGear = 0
			_ClutchOn = false
			_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+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+2])
		if _RPM>_Tune.Redline then 
			if _CGear<#_Tune.Ratios-2 then
				_RPM = _RPM-_Tune.RevBounce
			else
				_RPM = _RPM-_Tune.RevBounce*.5
			end
		end
		
		local TPsi = _TPsi/_TCount
		
		if _Tune.Aspiration ~= "Super" then 
			_Boost = _Boost + ((((((_HP*(_GThrot*1.2)/_Tune.Horsepower)/8)-(((_Boost/TPsi*(TPsi/15)))))*((8/_Tune.TurboSize)*2))/TPsi)*15)
			if _Boost < 0.05 then _Boost = 0.05 elseif _Boost > 2 then _Boost = 2 end
		else
			if _GThrot>sthrot then
				sthrot=math.min(_GThrot,sthrot+_Tune.Sensitivity)
			elseif _GThrot<sthrot then
				sthrot=math.max(_GThrot,sthrot-_Tune.Sensitivity)
			end
			_Boost = (_RPM/_Tune.Redline)*(.5+(1.5*sthrot))
		end
		
		
		local cTq = HPCache[_CGear+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 _Tune.Aspiration ~= "Natural" then
			local bTq = PSICache[_CGear+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
		
		local iComp =(car.DriveSeat.CFrame.lookVector.y)*cGrav
		if _CGear==-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
			
			--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 _Tune.Config == "AWD" 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 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 script.Parent.IsOn.Value then on=0 end
						local clutch=1
						if not _ClutchOn then clutch=0 end
						local throt = _GThrot * _GThrotShift
						local tq = _OutTorque
						
						--Apply AWD Vectoring
						if _Tune.Config == "AWD" then
							local bias = (_Tune.TorqueVector+1)/2
							if v.Name=="FL" or v.Name=="FR" then
								tq = tq*(1-bias)
							elseif v.Name=="RL" or v.Name=="RR" then
								tq = tq*bias
							end
						end
						
						--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==-1 then dir = -1 end
						v["#AV"].maxTorque=Vector3.new(math.abs(Ref.x),math.abs(Ref.y),math.abs(Ref.z))*tq*(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
					
					--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
	
	
	