local w=_Tune.FinalDrive local k=(w*30)/math.pi local u=(wDia*math.pi)/60 local X=CFrame.Angles(math.pi/2,-math.pi/2,0)local a=CFrame.Angles(0,math.pi,0)if not _Tune.Engine and _Tune.Electric then _Tune.Redline=_Tune.E_Redline _Tune.PeakRPM=_Tune.E_Trans2 _Tune.Turbochargers=0 _Tune.Superchargers=0 _Tune.Clutch=false _Tune.IdleRPM=0 _Tune.AutoShiftType="\068\067\084"_Tune.ShiftUpTime=.1 _Tune.ShiftDnTime=.1 end _TCount=_Tune.Turbochargers _TPsi=_Tune.T_Boost*_Tune.Turbochargers _SCount=_Tune.Superchargers _SPsi=_Tune.S_Boost*_Tune.Superchargers local y=_Tune.Horsepower local l=y*(((_TPsi*(_Tune.T_Efficiency/10))/7.5)/2)local U=y*(((_SPsi*(_Tune.S_Efficiency/10))/7.5)/2)local z,N=_Tune.PeakRPM,_Tune.MT_PeakRPM local I,j=_Tune.MH_CurveMult,_Tune.MT_CurveMult local K,B=_Tune.TH_CurveMult,_Tune.TT_CurveMult local F,n=_Tune.SH_CurveMult,_Tune.ST_CurveMult local P,S=_Tune.MH_PeakSharp,_Tune.MT_PeakSharp local Q,L=_Tune.TH_PeakSharp,_Tune.TT_PeakSharp local G,t=_Tune.SH_PeakSharp,_Tune.ST_PeakSharp local m={y,z;I;P,N;j;S}local W={l;z,K,Q;N,B,L}local R={U;z,F,G,N,n;t}function getCurve(w,k,u,X,a)w=w/1000 k=k/100 u=u/1000 return(-(w-u)^2*math.min(k/u^2,X^(u/k))+k)*(w-w^a/(a*u^(a-1)))end function getPeak(w)local k,u,X,a,y,l,U=w[1]/100,w[2]/1000,w[3],w[4],w[5]/1000,w[6],w[7]local z=(-(u-u)^2*math.min(k/u^2,X^(u/k))+k)*(u-u^a/(a*u^(a-1)))local N=(-(y-y)^2*math.min(k/y^2,l^(y/k))+k)*(y-y^U/(U*y^(U-1)))return z,N end local E,e=getPeak(m)local J,H=getPeak(W)local d,M=getPeak(R)function EngineCurve(k,u,X,a,y,l)local U,z,N,I,j,K,B=X[1],X[2],X[3],X[4],X[5],X[6],X[7]local F=math.max(getCurve(k,U,z,N,I)/(y/U),0)local n=math.max(getCurve(k,U,j,K,B)/(l/U),0)return F,(((n*(a/k))*_Tune.Ratios[u+1])*w)*hpScaling end local x=_Tune.E_Horsepower/100 local s=_Tune.E_Torque/100 local g=_Tune.E_Trans1/1000 local V=_Tune.E_Trans2/1000 local i=_Tune.E_Redline/1000 function elecHP(w)w=w/1000 local k=1e-09 if w<=g then k=((w/g)^_Tune.EH_FrontMult/(1/x))*(w/g)+((w/g)^(1/_Tune.EH_FrontMult)/(1/x))*(1-w/g)elseif g<w and w<V then k=x elseif V<=w then k=x-((w-V)/(i-V))^_Tune.EH_EndMult/(1/(x*(_Tune.EH_EndPercent/100)))else error("\n\t \091\078\067\084\058 \077\093\058 \068\114\105\118\101 \105\110\105\116\105\097\108\105\122\097\116\105\111\110 \102\097\105\108\101\100\033"..("\n\t    \065\110 \117\110\107\110\111\119\110 \101\114\114\111\114 \111\099\099\117\114\101\100 \119\104\101\110 \105\110\105\116\105\097\108\105\122\105\110\103 \101\108\101\099\116\114\105\099 \104\111\114\115\101\112\111\119\101\114\046"..("\n\t    \080\108\101\097\115\101 \115\101\110\100 \097 \115\099\114\101\101\110\115\104\111\116 \111\102 \116\104\105\115 \109\101\115\115\097\103\101 \116\111 \065\118\120\110\116\117\114\097\100\111\114\046"..("\n\t    \082\058 "..(w..("\044 \084\049\058 "..(g("\044 \084\050\058 ")..(V("\044 \076\058 ")..i("\046")))))))))end return k end function elecTQ(w)w=w/1000 local k=1e-09 if w<g then k=s elseif g<=w then k=s-((w-g)/(i-g))^_Tune.ET_EndMult/(1/(s*(_Tune.ET_EndPercent/100)))else error("\n\t \091\078\067\084\058 \077\093\058 \068\114\105\118\101 \105\110\105\116\105\097\108\105\122\097\116\105\111\110 \102\097\105\108\101\100\033"..("\n\t    \065\110 \117\110\107\110\111\119\110 \101\114\114\111\114 \111\099\099\117\114\101\100 \119\104\101\110 \105\110\105\116\105\097\108\105\122\105\110\103 \101\108\101\099\116\114\105\099 \116\111\114\113\117\101\046"..("\n\t    \080\108\101\097\115\101 \115\101\110\100 \097 \115\099\114\101\101\110\115\104\111\116 \111\102 \116\104\105\115 \109\101\115\115\097\103\101 \116\111 \065\118\120\110\116\117\114\097\100\111\114\046"..("\n\t    \082\058 "..(w..("\044 \084\049\058 "..(g("\044 \084\050\058 ")..(V("\044 \076\058 ")..i("\046")))))))))end return k end function ElecCurve(k,u)local X=math.max(elecHP(k),0)*100 local a=math.max(elecTQ(k),0)*100 if u~=0 then return X,math.max(((a*_Tune.Ratios[u+1])*w)*hpScaling,0)else return 0,0 end end local Y={}local c={}local b={}local o={}for w,k in pairs(_Tune.Ratios)do local u={}local X={}local a={}local y={}for k=0,math.ceil((_Tune.Redline+100)/100),1 do local l={}local U={}local z={}local N={}if k~=0 then if _Tune.Engine then l.Horsepower,l.Torque=EngineCurve(k*100,w-1,m,_Tune.M_EqPoint,E,e)if _TCount~=0 then z.Horsepower,z.Torque=EngineCurve(k*100,w-1,W,_Tune.M_EqPoint,J,H)else z.Horsepower,z.Torque=0,0 end if _SCount~=0 then N.Horsepower,N.Torque=EngineCurve(k*100,w-1,R,_Tune.M_EqPoint,d,M)else N.Horsepower,N.Torque=0,0 end else l.Horsepower,l.Torque=0,0 z.Horsepower,z.Torque=0,0 N.Horsepower,N.Torque=0,0 end if _Tune.Electric then U.Horsepower,U.Torque=ElecCurve(k*100,w-1)else U.Horsepower,U.Torque=0,0 end else l.Horsepower,l.Torque=0,0 U.Horsepower,U.Torque=0,0 z.Horsepower,z.Torque=0,0 N.Horsepower,N.Torque=0,0 end if _Tune.Engine then nhp,ntq=EngineCurve((k+1)*100,w-1,m,_Tune.M_EqPoint,E,e)if _TCount~=0 then thp,ttq=EngineCurve((k+1)*100,w-1,W,_Tune.M_EqPoint,J,H)else thp,ttq=0,0 end if _SCount~=0 then shp,stq=EngineCurve((k+1)*100,w-1,R,_Tune.M_EqPoint,d,M)else shp,stq=0,0 end else nhp,ntq=0,0 thp,ttq=0,0 shp,stq=0,0 end if _Tune.Electric then ehp,etq=ElecCurve((k+1)*100,w-1)else ehp,etq=0,0 end l.HpSlope,l.TqSlope=nhp-l.Horsepower,ntq-l.Torque U.HpSlope,U.TqSlope=ehp-U.Horsepower,etq-U.Torque z.HpSlope,z.TqSlope=thp-z.Horsepower,ttq-z.Torque N.HpSlope,N.TqSlope=shp-N.Horsepower,stq-N.Torque u[k]=l X[k]=U a[k]=z y[k]=N end table.insert(Y,u)table.insert(c,X)table.insert(b,a)table.insert(o,y)end wait()function Auto()local X=0 if Rear.Wheel.RotVelocity.Magnitude>X then X=Rear.Wheel.RotVelocity.Magnitude end if _IsOn then if _CGear==0 and not _Tune.NeutralRev then _CGear=1 _ClPressing=false end if _CGear>=1 then if(_CGear==1 and(_InBrake>0 and bike.DriveSeat.Velocity.Magnitude<10))and _Tune.NeutralRev then _CGear=0 _ClPressing=false elseif bike.DriveSeat.Velocity.Magnitude>10 then if _Tune.AutoShiftMode=="\082\080\077"and not _ClutchSlip then if _RPM>_Tune.PeakRPM+_Tune.AutoUpThresh then if not _ShiftUp and not _Shifting then _ShiftUp=true end elseif math.max(math.min((X*_Tune.Ratios[_CGear+1])*k,_Tune.Redline+100),_Tune.IdleRPM)<_Tune.PeakRPM-_Tune.AutoDownThresh and _CGear>1 then if not _ShiftDn and not _Shifting then _ShiftDn=true end end else if bike.DriveSeat.Velocity.Magnitude>math.ceil(((u*(_Tune.PeakRPM+_Tune.AutoUpThresh))/_Tune.Ratios[_CGear+1])/w)then if not _ShiftUp and not _Shifting then _ShiftUp=true end elseif bike.DriveSeat.Velocity.Magnitude<math.ceil(((u*(_Tune.PeakRPM-_Tune.AutoDownThresh))/_Tune.Ratios[_CGear+1])/w)and _CGear>1 then if not _ShiftDn and not _Shifting then _ShiftDn=true end end end end else if(_InThrot-_Tune.IdleThrottle/100>0 and bike.DriveSeat.Velocity.Magnitude<10)and _Tune.NeutralRev then _CGear=1 _ClPressing=false end end end end function Gear()local w=0 if Rear.Wheel.RotVelocity.Magnitude>w then w=Rear.Wheel.RotVelocity.Magnitude end if _ShiftUp and not _Shifting then local u if _TMode~="\077\097\110\117\097\108"then u=true end if _TMode=="\077\097\110\117\097\108"and(not _Tune.QuickShifter and not _ClPressing or not _ClPressing and(_Tune.QuickShifter and tick()-_BTick>_Tune.QuickShiftTime))or _CGear==#_Tune.Ratios-1 or _TMode~="\077\097\110\117\097\108"and not _IsOn then _ShiftUp=false return end local X=math.min(_CGear+1,#_Tune.Ratios)if _TMode~="\077\097\110\117\097\108"then _Shifting=true if _CGear>0 then if _Tune.AutoShiftType=="\068\067\084"then wait(_Tune.ShiftUpTime)elseif _Tune.AutoShiftType=="\082\101\118"then repeat wait()until _RPM<=math.max(math.min((w*_Tune.Ratios[X])*k,_Tune.Redline-_Tune.RevBounce),_Tune.IdleRPM)or not _IsOn or _ShiftDn end end end _ShiftUp=false _Shifting=false if _TMode~="\077\097\110\117\097\108"and not _IsOn then return end _CGear=math.min(_CGear+1,#_Tune.Ratios-1)if _TMode~="\077\097\110\117\097\108"or(_TMode=="\077\097\110\117\097\108"and(_CGear==1 or u))and _IsOn then _ClPressing=false end end if _ShiftDn and not _Shifting then local u if _TMode~="\077\097\110\117\097\108"then u=true end if _TMode=="\077\097\110\117\097\108"and(not _Tune.QuickShifter and not _ClPressing or not _ClPressing and(_Tune.QuickShifter and tick()-_TTick>_Tune.QuickShiftTime))or _CGear==0 or _TMode~="\077\097\110\117\097\108"and not _IsOn then _ShiftDn=false return end local X=math.min(_CGear,#_Tune.Ratios)if _TMode~="\077\097\110\117\097\108"then _Shifting=true if _CGear>1 then if _Tune.AutoShiftType=="\068\067\084"then wait(_Tune.ShiftDnTime)elseif _Tune.AutoShiftType=="\082\101\118"then repeat wait()until _RPM>=math.max(math.min((w*_Tune.Ratios[X])*k,_Tune.Redline-_Tune.RevBounce),_Tune.IdleRPM)or not _IsOn or _ShiftUp end end end _ShiftDn=false _Shifting=false if _TMode~="\077\097\110\117\097\108"and not _IsOn then return end _CGear=math.max(_CGear-1,0)if _TMode~="\077\097\110\117\097\108"or(_TMode=="\077\097\110\117\097\108"and(_CGear==0 or u))and _IsOn then _ClPressing=false end end end local T=1 local h=0 local A=false local r=tick()local f=tick()function Engine(w)local u=60/(1/w)if _TMode~="\077\097\110\117\097\108"and _Tune.SlipClutch then if _Tune.ABS and _ABS then if _SlipCount>=_Tune.SlipABSThres then _ClutchSlip=true else _ClutchSlip=false end else if tick()-f>=_Tune.SlipTimeThres then _ClutchSlip=true else _ClutchSlip=false end end else _ClutchSlip=false end if(_CGear==0 or _Shifting)and _IsOn then _ClPressing=true _Clutch=1 A=false end local X=_Tune.IdleRPM local a=_Tune.IdleRPM if _Tune.Stall and _Tune.Clutch then X=0 end if _Shifting and _ShiftUp then _GThrot=0 elseif _Shifting and _ShiftDn then _GThrot=_Tune.ShiftThrot/100 else _GThrot=_InThrot end _GBrake=_InBrake if not _IsOn then r=tick()X=0 a=0 _GThrot=_Tune.IdleThrottle/100 if _TMode~="\077\097\110\117\097\108"then _CGear=0 _ClPressing=true _Clutch=1 end end local y=0 if Rear.Wheel.RotVelocity.Magnitude>y then y=Rear.Wheel.RotVelocity.Magnitude end local l=0 if _Tune.Engine or _Tune.Electric then l=math.max(math.min((_RPM-_Tune.RevDecay*u)+((_Tune.RevDecay+_Tune.RevAccel)*_GThrot)*u,_Tune.Redline+100),a)end if l>_Tune.Redline then if _CGear<#_Tune.Ratios-2 then l=l-_Tune.RevBounce else l=l-_Tune.RevBounce*.5 end end local U=(y*_Tune.Ratios[_CGear+1])*k if _Tune.Clutch then if script.Parent.Values.AutoClutch.Value and _IsOn then if _Tune.ClutchType=="\067\108\117\116\099\104"then if _ClPressing or _ClutchSlip then _ClutchKick=1 end _ClutchKick=_ClutchKick*(_Tune.ClutchEngage/100)local w=math.max(((_RPM-_Tune.IdleRPM)*_Tune.ClutchRPMMult)/(_Tune.Redline-_Tune.IdleRPM),0)if _Tune.ClutchMode=="\078\101\119"then w=0 end _ClutchModulate=math.min(((script.Parent.Values.Velocity.Value.Magnitude/_Tune.SpeedEngage)/math.abs(_CGear)+w)-_ClutchKick,1)elseif _Tune.ClutchType=="\067\086\084"or _Tune.ClutchType=="\084\111\114\113\117\101\067\111\110\118\101\114\116\101\114"and _Tune.TQLock then if _GThrot-_Tune.IdleThrottle/100==0 and script.Parent.Values.Velocity.Value.Magnitude<_Tune.SpeedEngage or _GThrot-_Tune.IdleThrottle/100~=0 and(_RPM<_Tune.RPMEngage and U<_Tune.RPMEngage)then _ClutchModulate=math.min(_ClutchModulate*(_Tune.ClutchEngage/100),1)else _ClutchModulate=math.min(_ClutchModulate*(_Tune.ClutchEngage/100)+(1-_Tune.ClutchEngage/100),1)end elseif _Tune.ClutchType=="\084\111\114\113\117\101\067\111\110\118\101\114\116\101\114"and not _Tune.TQLock then _ClutchModulate=math.min((_RPM/_Tune.Redline)*.7,1)end if not _ClPressing and not _ClutchSlip then _Clutch=math.min(1-_ClutchModulate,1)else _Clutch=1 end A=_Clutch<=.01 or A else A=_Tune.Stall _Clutch=script.Parent.Values.Clutch.Value end else A=false if(not _ClPressing and not _ClutchSlip)and not _Shifting then _Clutch=0 else _Clutch=1 end end local z=math.max(math.min(l*_Clutch+U*(1-_Clutch),_Tune.Redline+100),X)local N=math.min(math.abs(z-_RPM)/(_Tune.Flywheel*u),.9)if _ClPressing or _ClutchSlip then N=0 end _RPM=_RPM*N+z*(1-N)if _RPM<=_Tune.IdleRPM/4 and(A and tick()-r>=.2)then script.Parent.IsOn.Value=not _Tune.Stall end _spLimit=-((_Tune.Redline+100)/(k*_Tune.Ratios[_CGear+1]))if _Tune.Limiter then _spLimit=math.min(_spLimit,-_Tune.SpeedLimit)end if _RPM>_Tune.Redline then if _CGear<#_Tune.Ratios-2 then _RPM=_RPM-_Tune.RevBounce else _RPM=_RPM-_Tune.RevBounce*.5 end end local I=_TPsi/_TCount local j=_GThrot if _Tune.Engine then if _TCount~=0 then _TBoost=_TBoost+(((((_HP*(j*1.2))/_Tune.Horsepower)/8-(_TBoost/I)*(I/15))*((8/(_Tune.T_Size/u))*2))/I)*15 if _TBoost<.05 then _TBoost=.05 elseif _TBoost>2 then _TBoost=2 end else _TBoost=0 end if _SCount~=0 then if j>h then h=math.min(j,h+_Tune.S_Sensitivity*u)elseif j<h then h=math.max(j,h-_Tune.S_Sensitivity*u)end _SBoost=(_RPM/_Tune.Redline)*(.5+1.5*h)else _SBoost=0 end else _TBoost=0 _SBoost=0 end if _Tune.Engine then local w=Y[_CGear+1][math.floor(math.min(_Tune.Redline,math.max(0,_RPM))/100)]_NH=w.Horsepower+w.HpSlope*(((_RPM-math.floor(_RPM/100))/100)%1)_NT=w.Torque+w.TqSlope*(((_RPM-math.floor(_RPM/100))/100)%1)if _TCount~=0 then local w=b[_CGear+1][math.floor(math.min(_Tune.Redline,math.max(0,_RPM))/100)]_TH=(w.Horsepower+w.HpSlope*(((_RPM-math.floor(_RPM/100))/100)%1))*(_TBoost/2)_TT=(w.Torque+w.TqSlope*(((_RPM-math.floor(_RPM/100))/100)%1))*(_TBoost/2)else _TH,_TT=0,0 end if _SCount~=0 then local w=o[_CGear+1][math.floor(math.min(_Tune.Redline,math.max(0,_RPM))/100)]_SH=(w.Horsepower+w.HpSlope*(((_RPM-math.floor(_RPM/100))/100)%1))*(_SBoost/2)_ST=(w.Torque+w.TqSlope*(((_RPM-math.floor(_RPM/100))/100)%1))*(_SBoost/2)else _SH,_ST=0,0 end _BH=_TH+_SH _BT=_TT+_ST else _NH,_NT=0,0 _TH,_TT=0,0 _SH,_ST=0,0 _BH,_BT=0,0 end if _Tune.Electric and _CGear~=0 then local w=c[_CGear+1][math.floor(math.min(_Tune.Redline,math.max(100,_RPM))/100)]_EH=w.Horsepower+w.HpSlope*(((_RPM-math.floor(_RPM/100))/100)%1)_ET=w.Torque+w.TqSlope*(((_RPM-math.floor(_RPM/100))/100)%1)else _EH,_ET=0,0 end _HP=(_NH+_BH)+_EH _OutTorque=(_NT+_BT)+_ET _fABSActive=false if _PBrake and bike.DriveSeat.Velocity.Magnitude<20 then Front.Axle.HingeConstraint.MotorMaxTorque=PBrakeForce*(60/workspace:GetRealPhysicsFPS())else if _CGear==0 and(bike.DriveSeat.Velocity.Magnitude<=10 and _Tune.NeutralRev)then Front.Axle.HingeConstraint.MotorMaxTorque=(FBrakeForce*_GThrot)*(60/workspace:GetRealPhysicsFPS())else local w=1 if _ABS and math.abs(Front.Wheel.RotVelocity.Magnitude*(Front.Wheel.Size.Y/2)-Front.Wheel.Velocity.Magnitude)-_Tune.ABSThreshold>0 then w=0 end if w<1 then _fABSActive=true end local k=FBrakeForce if _Tune.LinkedBrakes then local w=_Tune.BrakesRatio/100 k=k*w end Front.Axle.HingeConstraint.MotorMaxTorque=((k*_GBrake)*w)*(60/workspace:GetRealPhysicsFPS())end end _TCSActive=false _rABSActive=false if _PBrake and bike.DriveSeat.Velocity.Magnitude>=20 then _SlipCount=_Tune.SlipABSThres f=tick()-_Tune.SlipTimeThres Rear.Axle.HingeConstraint.MotorMaxTorque=PBrakeForce*(60/workspace:GetRealPhysicsFPS())Rear.Axle.HingeConstraint.MotorMaxAcceleration=9000000000.0 Rear.Axle.HingeConstraint.AngularVelocity=0 else if _CGear==0 and(bike.DriveSeat.Velocity.Magnitude<=10 and _Tune.NeutralRev)then f=tick()_SlipCount=0 Rear.Axle.HingeConstraint.MotorMaxTorque=math.min(500*_GBrake+RBrakeForce*_GThrot,500)*(60/workspace:GetRealPhysicsFPS())Rear.Axle.HingeConstraint.AngularVelocity=(7*_GBrake)*(1-_GThrot)elseif _GBrake==0 then f=tick()_SlipCount=0 local w=1 if not script.Parent.IsOn.Value then w=0 end local k=_GThrot local u=1 if _ClPressing then u=0 end local X=1 if _TCS then X=1-math.min(math.max(0,math.abs(Rear.Wheel.RotVelocity.Magnitude*(wDia/2)-Rear.Wheel.Velocity.Magnitude)-_Tune.TCSThreshold)/_Tune.TCSGradient,1)*(1-_Tune.TCSLimit/100)end _TCSAmt=X if X<1 then _TCSAmt=X _TCSActive=true end Rear.Axle.HingeConstraint.MotorMaxTorque=(((((_OutTorque*k)*X)*w)*u)*(60/workspace:GetRealPhysicsFPS()))*(1+(Rear.Wheel.RotVelocity.Magnitude/(120-workspace:GetRealPhysicsFPS()))^((1-_Tune.Drag)*1.15+((1-_Tune.Drag)*.07)*(1-60/workspace:GetRealPhysicsFPS())))Rear.Axle.HingeConstraint.MotorMaxAcceleration=_RPM*(math.pi/30)Rear.Axle.HingeConstraint.AngularVelocity=_spLimit else local w=1 if math.abs(Rear.Wheel.RotVelocity.Magnitude*(wDia/2)-Rear.Wheel.Velocity.Magnitude)-_Tune.ABSThreshold>0 then if _ABS then w=0 _SlipCount=_SlipCount+1 end else f=tick()end if w<1 then _rABSActive=true end local k=RBrakeForce if _Tune.LinkedBrakes then local w=_Tune.BrakesRatio/100 k=k*(1-w)end Rear.Axle.HingeConstraint.MotorMaxTorque=((k*_GBrake)*w)*(60/workspace:GetRealPhysicsFPS())Rear.Axle.HingeConstraint.MotorMaxAcceleration=9000000000.0 Rear.Axle.HingeConstraint.AngularVelocity=0 end end end


	local fFD = _Tune.FinalDrive
	local fFDr = fFD*30/math.pi
	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)
	
	--Electric Only Setup
	
	if not _Tune.Engine and _Tune.Electric then 
		_Tune.Redline = _Tune.E_Redline 
		_Tune.PeakRPM = _Tune.E_Trans2 
		_Tune.Turbochargers = 0
		_Tune.Superchargers = 0
		_Tune.Clutch = false 
		_Tune.IdleRPM = 0 
		_Tune.AutoShiftType = "DCT" 
		_Tune.ShiftUpTime = 0.1 
		_Tune.ShiftDnTime = 0.1 
	end
	
	--Aspiration Setup
	
	_TCount = _Tune.Turbochargers
	_TPsi = _Tune.T_Boost*_Tune.Turbochargers
	
	_SCount = _Tune.Superchargers
	_SPsi = _Tune.S_Boost*_Tune.Superchargers
	
	--Engine Curve
	
	local HP_M = _Tune.Horsepower
	local HP_T = HP_M*(((_TPsi*(_Tune.T_Efficiency/10))/7.5)/2)
	local HP_S = HP_M*(((_SPsi*(_Tune.S_Efficiency/10))/7.5)/2)
	local PK_H, PK_T = _Tune.PeakRPM, _Tune.MT_PeakRPM
	local MC_H, MC_T = _Tune.MH_CurveMult, _Tune.MT_CurveMult
	local TC_H, TC_T = _Tune.TH_CurveMult, _Tune.TT_CurveMult
	local SC_H, SC_T = _Tune.SH_CurveMult, _Tune.ST_CurveMult
	local MP_H, MP_T = _Tune.MH_PeakSharp, _Tune.MT_PeakSharp
	local TP_H, TP_T = _Tune.TH_PeakSharp, _Tune.TT_PeakSharp
	local SP_H, SP_T = _Tune.SH_PeakSharp, _Tune.ST_PeakSharp
	local V_MT = {HP_M,PK_H,MC_H,MP_H,PK_T,MC_T,MP_T}
	local V_TC = {HP_T,PK_H,TC_H,TP_H,PK_T,TC_T,TP_T}
	local V_SC = {HP_S,PK_H,SC_H,SP_H,PK_T,SC_T,SP_T}
	
	function getCurve(RPM,HP,Peak,CurveMult,Sharpness)
		RPM=RPM/1000
		HP=HP/100
		Peak=Peak/1000
		return ((-(RPM-Peak)^2)*math.min(HP/(Peak^2),CurveMult^(Peak/HP))+HP)*(RPM-((RPM^Sharpness)/(Sharpness*Peak^(Sharpness-1))))
	end
	
	function getPeak(V)
		local HP,Peak_H,CurveMult_H,Sharpness_H,Peak_T,CurveMult_T,Sharpness_T=V[1]/100,V[2]/1000,V[3],V[4],V[5]/1000,V[6],V[7]
		local hp=((-(Peak_H-Peak_H)^2)*math.min(HP/(Peak_H^2),CurveMult_H^(Peak_H/HP))+HP)*(Peak_H-((Peak_H^Sharpness_H)/(Sharpness_H*Peak_H^(Sharpness_H-1))))
		local tq=((-(Peak_T-Peak_T)^2)*math.min(HP/(Peak_T^2),CurveMult_T^(Peak_T/HP))+HP)*(Peak_T-((Peak_T^Sharpness_T)/(Sharpness_T*Peak_T^(Sharpness_T-1))))
		return hp, tq
	end
	
	local PeakHP_N, PeakTQ_N = getPeak(V_MT)
	local PeakHP_T, PeakTQ_T = getPeak(V_TC)
	local PeakHP_S, PeakTQ_S = getPeak(V_SC)
	
	--Plot Current Horsepower
	function EngineCurve(x,gear,V,eq,peakhp,peaktq)
		local hp,peak_h,cm_h,sharp_h,peak_t,cm_t,sharp_t=V[1],V[2],V[3],V[4],V[5],V[6],V[7]
		local hp_r=(math.max(getCurve(x,hp,peak_h,cm_h,sharp_h)/(peakhp/hp),0))
		local tq_r=(math.max(getCurve(x,hp,peak_t,cm_t,sharp_t)/(peaktq/hp),0))
		return hp_r,((tq_r*(eq/x))*_Tune.Ratios[gear+1]*fFD*hpScaling)
	end
	
	--Electric Curve
	
	local EHP=_Tune.E_Horsepower/100
	local ETQ=_Tune.E_Torque/100
	local ETrans1=_Tune.E_Trans1/1000
	local ETrans2=_Tune.E_Trans2/1000
	local ELimit=_Tune.E_Redline/1000 
	
	function elecHP(RPM)
		RPM=RPM/1000
		local retVal=1e-9
		if RPM<=ETrans1 then
			retVal=((((RPM/ETrans1)^_Tune.EH_FrontMult)/(1/EHP))*(RPM/ETrans1))+((((RPM/ETrans1)^(1/_Tune.EH_FrontMult))/(1/EHP))*(1-(RPM/ETrans1)))
		elseif ETrans1<RPM and RPM<ETrans2 then
			retVal=EHP
		elseif ETrans2<=RPM then
			retVal=EHP-(((RPM-ETrans2)/(ELimit-ETrans2))^_Tune.EH_EndMult)/(1/(EHP*(_Tune.EH_EndPercent/100)))
		else
			error( "\n\t [NCT: M]: Drive initialization failed!"
			.."\n\t    An unknown error occured when initializing electric horsepower."
			.."\n\t    Please send a screenshot of this message to Avxnturador."
			.."\n\t    R: "..RPM..", T1: "..ETrans1", T2: "..ETrans2", L: "..ELimit".")
		end
		return retVal
	end
	
	function elecTQ(RPM)
		RPM=RPM/1000
		local retVal=1e-9
		if RPM<ETrans1 then
			retVal=ETQ
		elseif ETrans1<=RPM then
			retVal=ETQ-(((RPM-ETrans1)/(ELimit-ETrans1))^_Tune.ET_EndMult)/(1/(ETQ*(_Tune.ET_EndPercent/100)))
		else
			error( "\n\t [NCT: M]: Drive initialization failed!"
			.."\n\t    An unknown error occured when initializing electric torque."
			.."\n\t    Please send a screenshot of this message to Avxnturador."
			.."\n\t    R: "..RPM..", T1: "..ETrans1", T2: "..ETrans2", L: "..ELimit".")
		end
		return retVal
	end
	
	--Plot Current Electric Horsepower
	function ElecCurve(x,gear)
		local hp=(math.max(elecHP(x),0))*100
		local tq=(math.max(elecTQ(x),0))*100
		if gear~=0 then
			return hp,math.max(tq*_Tune.Ratios[gear+1]*fFD*hpScaling,0)
		else
			return 0,0
		end
	end
	
	--Output Cache	
	local NCache = {}
	local ECache = {}
	local TCache = {}
	local SCache = {}
	
	for gear,ratio in pairs(_Tune.Ratios) do
		local nhpPlot = {}
		local ehpPlot = {}
		local thpPlot = {}
		local shpPlot = {}
		for rpm = 0, math.ceil((_Tune.Redline+100)/100) do
			local ntqPlot = {}
			local etqPlot = {}
			local ttqPlot = {}
			local stqPlot = {}
			if rpm~=0 then
				if _Tune.Engine then
					ntqPlot.Horsepower,ntqPlot.Torque = EngineCurve(rpm*100,gear-1,V_MT,_Tune.M_EqPoint,PeakHP_N,PeakTQ_N)
					if _TCount~=0 then
						ttqPlot.Horsepower,ttqPlot.Torque = EngineCurve(rpm*100,gear-1,V_TC,_Tune.M_EqPoint,PeakHP_T,PeakTQ_T)
					else
						ttqPlot.Horsepower,ttqPlot.Torque = 0,0
					end
					if _SCount~=0 then
						stqPlot.Horsepower,stqPlot.Torque = EngineCurve(rpm*100,gear-1,V_SC,_Tune.M_EqPoint,PeakHP_S,PeakTQ_S)
					else
						stqPlot.Horsepower,stqPlot.Torque = 0,0
					end
				else
					ntqPlot.Horsepower,ntqPlot.Torque = 0,0
					ttqPlot.Horsepower,ttqPlot.Torque = 0,0
					stqPlot.Horsepower,stqPlot.Torque = 0,0
				end
				if _Tune.Electric then
					etqPlot.Horsepower,etqPlot.Torque = ElecCurve(rpm*100,gear-1)
				else
					etqPlot.Horsepower,etqPlot.Torque = 0,0
				end
			else
				ntqPlot.Horsepower,ntqPlot.Torque = 0,0
				etqPlot.Horsepower,etqPlot.Torque = 0,0
				ttqPlot.Horsepower,ttqPlot.Torque = 0,0
				stqPlot.Horsepower,stqPlot.Torque = 0,0
			end
			if _Tune.Engine then
				nhp,ntq = EngineCurve((rpm+1)*100,gear-1,V_MT,_Tune.M_EqPoint,PeakHP_N,PeakTQ_N)
				if _TCount~=0 then
					thp,ttq = EngineCurve((rpm+1)*100,gear-1,V_TC,_Tune.M_EqPoint,PeakHP_T,PeakTQ_T)
				else
					thp,ttq = 0,0
				end
				if _SCount~=0 then
					shp,stq = EngineCurve((rpm+1)*100,gear-1,V_SC,_Tune.M_EqPoint,PeakHP_S,PeakTQ_S)
				else
					shp,stq = 0,0
				end
			else
				nhp,ntq = 0,0
				thp,ttq = 0,0
				shp,stq = 0,0
			end
			if _Tune.Electric then
				ehp,etq = ElecCurve((rpm+1)*100,gear-1)
			else
				ehp,etq = 0,0
			end
			ntqPlot.HpSlope,ntqPlot.TqSlope = (nhp-ntqPlot.Horsepower),(ntq-ntqPlot.Torque)
			etqPlot.HpSlope,etqPlot.TqSlope = (ehp-etqPlot.Horsepower),(etq-etqPlot.Torque)
			ttqPlot.HpSlope,ttqPlot.TqSlope = (thp-ttqPlot.Horsepower),(ttq-ttqPlot.Torque)
			stqPlot.HpSlope,stqPlot.TqSlope = (shp-stqPlot.Horsepower),(stq-stqPlot.Torque)
			nhpPlot[rpm] = ntqPlot
			ehpPlot[rpm] = etqPlot
			thpPlot[rpm] = ttqPlot
			shpPlot[rpm] = stqPlot
		end
		table.insert(NCache,nhpPlot)
		table.insert(ECache,ehpPlot)
		table.insert(TCache,thpPlot)
		table.insert(SCache,shpPlot)
	end
	
	--Powertrain
	wait()

	function Auto()
		local maxSpin=0
		if Rear.Wheel.RotVelocity.Magnitude>maxSpin then maxSpin = Rear.Wheel.RotVelocity.Magnitude end
		if _IsOn then
			if _CGear == 0 and not _Tune.NeutralRev then _CGear = 1 _ClPressing = false end
			if _CGear >= 1 then
				if (_CGear==1 and _InBrake > 0 and bike.DriveSeat.Velocity.Magnitude < 10) and _Tune.NeutralRev then
					_CGear = 0 _ClPressing = false
				elseif bike.DriveSeat.Velocity.Magnitude > 10 then
					if _Tune.AutoShiftMode == "RPM" and not _ClutchSlip then
						if _RPM>(_Tune.PeakRPM+_Tune.AutoUpThresh) then
							if not _ShiftUp and not _Shifting then _ShiftUp = true end
						elseif math.max(math.min(maxSpin*_Tune.Ratios[_CGear+1]*fFDr,_Tune.Redline+100),_Tune.IdleRPM)<(_Tune.PeakRPM-_Tune.AutoDownThresh) and _CGear>1 then
							if not _ShiftDn and not _Shifting then _ShiftDn = true end 
						end
					else
						if bike.DriveSeat.Velocity.Magnitude > math.ceil(wDRatio*(_Tune.PeakRPM+_Tune.AutoUpThresh)/_Tune.Ratios[_CGear+1]/fFD) then
							if not _ShiftUp and not _Shifting then _ShiftUp = true end
						elseif bike.DriveSeat.Velocity.Magnitude < math.ceil(wDRatio*(_Tune.PeakRPM-_Tune.AutoDownThresh)/_Tune.Ratios[_CGear+1]/fFD) and _CGear>1 then
							if not _ShiftDn and not _Shifting then _ShiftDn = true end
						end
					end
				end
			else
				if (_InThrot-(_Tune.IdleThrottle/100) > 0 and bike.DriveSeat.Velocity.Magnitude < 10) and _Tune.NeutralRev then
					_CGear = 1 _ClPressing = false
				end
			end
		end 
	end
	
	function Gear()
		local maxSpin=0
		if Rear.Wheel.RotVelocity.Magnitude>maxSpin then maxSpin = Rear.Wheel.RotVelocity.Magnitude end
		if _ShiftUp and not _Shifting then
			local AutoCheck if _TMode~="Manual" then AutoCheck = true end
			if (_TMode == "Manual" and ((not _Tune.QuickShifter and not _ClPressing) or (not _ClPressing and (_Tune.QuickShifter and tick()-_BTick>_Tune.QuickShiftTime)))) or _CGear == #_Tune.Ratios-1 or (_TMode ~= "Manual" and not _IsOn) then _ShiftUp = false return end
			local NextGear = math.min(_CGear+1,#_Tune.Ratios)
			if _TMode~="Manual" then
				_Shifting = true
				if _CGear>0 then 
					if _Tune.AutoShiftType=="DCT" then 
						wait(_Tune.ShiftUpTime)
					elseif _Tune.AutoShiftType=="Rev" then
						repeat wait() until _RPM<=math.max(math.min(maxSpin*_Tune.Ratios[NextGear]*fFDr,_Tune.Redline-_Tune.RevBounce),_Tune.IdleRPM) or not _IsOn or _ShiftDn 
					end
				end
			end
			_ShiftUp = false
			_Shifting = false
			if _TMode ~= "Manual" and not _IsOn then return end
			_CGear = math.min(_CGear+1,#_Tune.Ratios-1)
			if _TMode ~= "Manual" or (_TMode == "Manual" and (_CGear == 1 or AutoCheck)) and _IsOn then _ClPressing = false end
		end
		if _ShiftDn and not _Shifting then
			local AutoCheck if _TMode~="Manual" then AutoCheck = true end
			if (_TMode == "Manual" and ((not _Tune.QuickShifter and not _ClPressing) or (not _ClPressing and (_Tune.QuickShifter and tick()-_TTick>_Tune.QuickShiftTime)))) or _CGear == 0 or (_TMode ~= "Manual" and not _IsOn) then _ShiftDn = false return end
			local PrevGear = math.min(_CGear,#_Tune.Ratios)
			if _TMode~="Manual" then
				_Shifting = true
				if _CGear>1 then 
					if _Tune.AutoShiftType=="DCT" then 
						wait(_Tune.ShiftDnTime)
					elseif _Tune.AutoShiftType=="Rev" then
						repeat wait() until _RPM>=math.max(math.min(maxSpin*_Tune.Ratios[PrevGear]*fFDr,_Tune.Redline-_Tune.RevBounce),_Tune.IdleRPM) or not _IsOn or _ShiftUp
					end
				end
			end
			_ShiftDn = false
			_Shifting = false
			if _TMode ~= "Manual" and not _IsOn then return end
			_CGear = math.max(_CGear-1,0)
			if _TMode ~= "Manual" or (_TMode == "Manual" and (_CGear == 0 or AutoCheck)) and _IsOn then _ClPressing = false end
		end
	end

	local tqTCS = 1
	local sthrot = 0
	local _StallOK = false
	local ticc = tick()
	local bticc = tick()
	--Apply Power
	function Engine(dt)
		local deltaTime = (60/(1/dt))
		--Determine Clutch Slip
		if _TMode~="Manual" and _Tune.SlipClutch then
			if _Tune.ABS and _ABS then
				if _SlipCount >= _Tune.SlipABSThres then _ClutchSlip = true else _ClutchSlip = false end
			else
				if tick()-bticc >= _Tune.SlipTimeThres then _ClutchSlip = true else _ClutchSlip = false end
			end
		else
			_ClutchSlip = false
		end
		
		--Neutral Gear
		if ((_CGear == 0 or _Shifting) and _IsOn) then 
			_ClPressing = true
			_Clutch = 1
			_StallOK = false
		end
		
		local revMin = _Tune.IdleRPM 
		local goalMin = _Tune.IdleRPM 
		if _Tune.Stall and _Tune.Clutch then revMin = 0 end
		
		if _Shifting and _ShiftUp then 
			_GThrot = 0
		elseif _Shifting and _ShiftDn then
			_GThrot = (_Tune.ShiftThrot/100)
		else
			_GThrot = _InThrot
		end
		_GBrake = _InBrake
		
		if not _IsOn then 
			ticc = tick()
			revMin = 0 
			goalMin = 0
			_GThrot = _Tune.IdleThrottle/100
			if _TMode~="Manual" then 
				_CGear = 0 
				_ClPressing = true 
				_Clutch = 1 
			end
		end
		
		--Determine RPM
		local maxSpin=0
		if Rear.Wheel.RotVelocity.Magnitude>maxSpin then maxSpin = Rear.Wheel.RotVelocity.Magnitude end
		local _GoalRPM=0
		
		if _Tune.Engine or _Tune.Electric then
			_GoalRPM = math.max(math.min((_RPM-_Tune.RevDecay*deltaTime)+((_Tune.RevDecay+_Tune.RevAccel)*_GThrot*deltaTime),_Tune.Redline+100),goalMin)
		end
		
		if _GoalRPM>_Tune.Redline then 
			if _CGear<#_Tune.Ratios-2 then
				_GoalRPM = _GoalRPM-_Tune.RevBounce
			else
				_GoalRPM = _GoalRPM-_Tune.RevBounce*.5
			end
		end
		
		local _WheelRPM = maxSpin*_Tune.Ratios[_CGear+1]*fFDr
		
		--Clutch Calculation
		if _Tune.Clutch then
			if script.Parent.Values.AutoClutch.Value and _IsOn then
				if _Tune.ClutchType == "Clutch" then
					if _ClPressing or _ClutchSlip then _ClutchKick = 1 end
					_ClutchKick = _ClutchKick*(_Tune.ClutchEngage/100)		
					local ClRPMInfluence = math.max((_RPM-_Tune.IdleRPM)*_Tune.ClutchRPMMult/(_Tune.Redline-_Tune.IdleRPM),0)
					if _Tune.ClutchMode == "New" then ClRPMInfluence = 0 end
					_ClutchModulate = math.min(((((script.Parent.Values.Velocity.Value.Magnitude/_Tune.SpeedEngage)/math.abs(_CGear)) + ClRPMInfluence) - _ClutchKick), 1)
				elseif _Tune.ClutchType == "CVT" or (_Tune.ClutchType == "TorqueConverter" and _Tune.TQLock) then
					if (_GThrot-(_Tune.IdleThrottle/100)==0 and script.Parent.Values.Velocity.Value.Magnitude<_Tune.SpeedEngage) or (_GThrot-(_Tune.IdleThrottle/100)~=0 and (_RPM < _Tune.RPMEngage and _WheelRPM < _Tune.RPMEngage)) then
						_ClutchModulate = math.min(_ClutchModulate*(_Tune.ClutchEngage/100), 1)
					else
						_ClutchModulate = math.min(_ClutchModulate*(_Tune.ClutchEngage/100)+(1-(_Tune.ClutchEngage/100)), 1)
					end
				elseif _Tune.ClutchType == "TorqueConverter" and not _Tune.TQLock then
					_ClutchModulate = math.min((_RPM/_Tune.Redline)*0.7, 1)
				end
				if not _ClPressing and not _ClutchSlip then _Clutch = math.min(1-_ClutchModulate,1) else _Clutch = 1 end
				_StallOK = (_Clutch<=0.01) or _StallOK
			else
				_StallOK = _Tune.Stall
				_Clutch = script.Parent.Values.Clutch.Value
			end
		else
			_StallOK = false
			if (not _ClPressing and not _ClutchSlip) and not _Shifting then _Clutch = 0 else _Clutch = 1 end
		end
		
		local aRPM = math.max(math.min((_GoalRPM*_Clutch) + (_WheelRPM*(1-_Clutch)),_Tune.Redline+100),revMin)
		local clutchP = math.min(math.abs(aRPM-_RPM)/(_Tune.Flywheel*deltaTime),.9)
		if _ClPressing or _ClutchSlip then clutchP = 0 end
		_RPM = _RPM*clutchP  +  aRPM*(1-clutchP)
		
		if _RPM<=(_Tune.IdleRPM/4) and _StallOK and (tick()-ticc>=0.2) then script.Parent.IsOn.Value = not _Tune.Stall end
		
		--Rev Limiter
		_spLimit = -((_Tune.Redline+100)/(fFDr*_Tune.Ratios[_CGear+1]))
		if _Tune.Limiter then _spLimit = math.min(_spLimit,-_Tune.SpeedLimit) end
		if _RPM>_Tune.Redline then 
			if _CGear<#_Tune.Ratios-2 then
				_RPM = _RPM-_Tune.RevBounce
			else
				_RPM = _RPM-_Tune.RevBounce*.5
			end
		end
		
		--Aspiration
		local TPsi = _TPsi/_TCount
		
		local _BThrot = _GThrot
		
		if _Tune.Engine then
			if _TCount~=0 then
				_TBoost = _TBoost + ((((((_HP*(_BThrot*1.2)/_Tune.Horsepower)/8)-(((_TBoost/TPsi*(TPsi/15)))))*((8/(_Tune.T_Size/(deltaTime)))*2))/TPsi)*15)
				if _TBoost < 0.05 then _TBoost = 0.05 elseif _TBoost > 2 then _TBoost = 2 end
			else
				_TBoost = 0
			end
			if _SCount~=0 then
				if _BThrot>sthrot then
					sthrot=math.min(_BThrot,sthrot+_Tune.S_Sensitivity*deltaTime)
				elseif _BThrot<sthrot then
					sthrot=math.max(_BThrot,sthrot-_Tune.S_Sensitivity*deltaTime)
				end
				_SBoost = (_RPM/_Tune.Redline)*(.5+(1.5*sthrot))
			else
				_SBoost = 0
			end
		else
			_TBoost = 0
			_SBoost = 0
		end
		
		--Torque calculations
		if _Tune.Engine then
			local cTq = NCache[_CGear+1][math.floor(math.min(_Tune.Redline,math.max(0,_RPM))/100)]
			_NH = cTq.Horsepower+(cTq.HpSlope*(((_RPM-math.floor(_RPM/100))/100)%1))
			_NT = cTq.Torque+(cTq.TqSlope*(((_RPM-math.floor(_RPM/100))/100)%1))
			if _TCount~=0 then
				local tTq = TCache[_CGear+1][math.floor(math.min(_Tune.Redline,math.max(0,_RPM))/100)]
				_TH = (tTq.Horsepower+(tTq.HpSlope*(((_RPM-math.floor(_RPM/100))/100)%1)))*(_TBoost/2)
				_TT = (tTq.Torque+(tTq.TqSlope*(((_RPM-math.floor(_RPM/100))/100)%1)))*(_TBoost/2)
			else
				_TH,_TT = 0,0
			end
			if _SCount~=0 then
				local sTq = SCache[_CGear+1][math.floor(math.min(_Tune.Redline,math.max(0,_RPM))/100)]
				_SH = (sTq.Horsepower+(sTq.HpSlope*(((_RPM-math.floor(_RPM/100))/100)%1)))*(_SBoost/2)
				_ST = (sTq.Torque+(sTq.TqSlope*(((_RPM-math.floor(_RPM/100))/100)%1)))*(_SBoost/2)
			else
				_SH,_ST = 0,0
			end
			_BH = _TH+_SH
			_BT = _TT+_ST
		else
			_NH,_NT = 0,0
			_TH,_TT = 0,0
			_SH,_ST = 0,0
			_BH,_BT = 0,0
		end
		
		if _Tune.Electric and _CGear~=0 then
			local eTq = ECache[_CGear+1][math.floor(math.min(_Tune.Redline,math.max(100,_RPM))/100)]
			_EH = eTq.Horsepower+(eTq.HpSlope*(((_RPM-math.floor(_RPM/100))/100)%1))
			_ET = eTq.Torque+(eTq.TqSlope*(((_RPM-math.floor(_RPM/100))/100)%1))
		else
			_EH,_ET = 0,0
		end
		
		_HP = _NH + _BH + _EH
		_OutTorque = _NT + _BT + _ET
		
		--Update Wheels
		
		--Front

		_fABSActive = false
		--Output
		if _PBrake and bike.DriveSeat.Velocity.Magnitude<20 then
			--PBrake
			Front.Axle.HingeConstraint.MotorMaxTorque=PBrakeForce*(60/workspace:GetRealPhysicsFPS())
		else
			if _CGear == 0 and bike.DriveSeat.Velocity.Magnitude <= 10 and _Tune.NeutralRev then
				Front.Axle.HingeConstraint.MotorMaxTorque=FBrakeForce*_GThrot*(60/workspace:GetRealPhysicsFPS())
			else
				--Apply ABS
				local ftqABS = 1
				if _ABS and math.abs(Front.Wheel.RotVelocity.Magnitude*(Front.Wheel.Size.Y/2) - Front.Wheel.Velocity.Magnitude)-_Tune.ABSThreshold>0 then ftqABS = 0 end
				if ftqABS < 1 then _fABSActive = true end
				local brake = FBrakeForce
				if _Tune.LinkedBrakes then
					local bias = _Tune.BrakesRatio/100
					brake = brake*bias
				end
				Front.Axle.HingeConstraint.MotorMaxTorque=brake*_GBrake*ftqABS*(60/workspace:GetRealPhysicsFPS())
			end
		end
		
		--Rear
		
		_TCSActive = false
		_rABSActive = false
		--Output
		if _PBrake and bike.DriveSeat.Velocity.Magnitude>=20 then
			--PBrake
			_SlipCount = _Tune.SlipABSThres
			bticc = tick()-_Tune.SlipTimeThres
			Rear.Axle.HingeConstraint.MotorMaxTorque=PBrakeForce*(60/workspace:GetRealPhysicsFPS())
			Rear.Axle.HingeConstraint.MotorMaxAcceleration=9e9
			Rear.Axle.HingeConstraint.AngularVelocity=0
		else
			--Apply Power
			if _CGear == 0 and bike.DriveSeat.Velocity.Magnitude <= 10 and _Tune.NeutralRev then
				bticc = tick()
				_SlipCount = 0
				Rear.Axle.HingeConstraint.MotorMaxTorque=math.min((500*_GBrake)+(RBrakeForce*_GThrot),500)*(60/workspace:GetRealPhysicsFPS())
				Rear.Axle.HingeConstraint.AngularVelocity=7*_GBrake*(1-_GThrot)
			elseif _GBrake==0 then
				bticc = tick()
				_SlipCount = 0
				local on=1
				if not script.Parent.IsOn.Value then on=0 end
				local throt = _GThrot
				local clutch=1
				if _ClPressing then clutch=0 end
						
				--Apply TCS
				local tqTCS = 1
				if _TCS then tqTCS = 1-(math.min(math.max(0,math.abs(Rear.Wheel.RotVelocity.Magnitude*(wDia/2) - Rear.Wheel.Velocity.Magnitude)-_Tune.TCSThreshold)/_Tune.TCSGradient,1)*(1-(_Tune.TCSLimit/100))) end
				_TCSAmt = tqTCS
				if tqTCS < 1 then
					_TCSAmt = tqTCS
					_TCSActive = true
				end
				
				--Update Forces
				Rear.Axle.HingeConstraint.MotorMaxTorque=_OutTorque*throt*tqTCS*on*clutch*(60/workspace:GetRealPhysicsFPS())*(1+(Rear.Wheel.RotVelocity.Magnitude/(120-workspace:GetRealPhysicsFPS()))^(((1-_Tune.Drag)*1.15)+(((1-_Tune.Drag)*.07)*(1-(60/workspace:GetRealPhysicsFPS())))))
				Rear.Axle.HingeConstraint.MotorMaxAcceleration=_RPM*(math.pi/30)
				Rear.Axle.HingeConstraint.AngularVelocity=_spLimit
			--Brakes
			else
				--Apply ABS
				local rtqABS = 1
				if math.abs(Rear.Wheel.RotVelocity.Magnitude*(wDia/2) - Rear.Wheel.Velocity.Magnitude)-_Tune.ABSThreshold>0 then 
					if _ABS then rtqABS = 0 _SlipCount = _SlipCount + 1 end
				else
					bticc = tick()
				end
				if rtqABS < 1 then _rABSActive = true end
				local brake = RBrakeForce
				if _Tune.LinkedBrakes then
					local bias = _Tune.BrakesRatio/100
					brake = brake*(1-bias)
				end
				
				Rear.Axle.HingeConstraint.MotorMaxTorque=brake*_GBrake*rtqABS*(60/workspace:GetRealPhysicsFPS())
				Rear.Axle.HingeConstraint.MotorMaxAcceleration=9e9
				Rear.Axle.HingeConstraint.AngularVelocity=0
			end
		end
	end
