script.Parent:WaitForChild("\067\097\114")script.Parent:WaitForChild("\073\115\079\110")script.Parent:WaitForChild("\067\111\110\116\114\111\108\115\079\112\101\110")script.Parent:WaitForChild("\086\097\108\117\101\115")local n=game.Players.LocalPlayer local F=n:GetMouse()local C=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local a=script.Parent.Car.Value local E=require(a["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local l=script.Parent.Version:WaitForChild("\084\101\120\116\076\097\098\101\108")l.Parent=script.Parent local O=E.WeightScaling*10 local i=E.BrakeForce*E.BrakeBias local f=E.BrakeForce*(1-E.BrakeBias)local A=E.PBrakeForce*E.PBrakeBias local g=E.PBrakeForce*(1-E.PBrakeBias)local p=E.EBrakeForce local G=E.SteerOuter local T=E.SteerInner local M=E.RSteerOuter local K=E.RSteerInner if not workspace:PGSIsEnabled()then error("\080\071\083 \105\115 \110\111\116 \101\110\097\098\108\101\100\058 \065-\067\104\097\115\115\105\115 \119\105\108\108 \110\111\116 \119\111\114\107\046")end local I=E.AutoStart if E.AutoStart and(E.Engine or E.Electric)then script.Parent.IsOn.Value=true end local y=0 local w=0 local u=0 local D=0 local v=E.IdleThrottle/100 local q=0 local L=0 local U=0 local c=false local B=false local j=0 local k=0 local W=0 local s=0 local N=0 local V=0 local X=0 local Y=X local e=false local z=false local h=false local P=0 local r=0 local Z=0 local d=0 local Q=0 local J=0 local m=0 local t=0 local o=0 local S=0 local x=0 local R=0 local H=0 local b=0 local np=0 local Fp=0 local Cp=0 local ap=0 local Ep=E.TransModes[1]local lp=false local Op=false local ip=false local fp=false local Ap=E.TCSEnabled local gp=false local pp=0 local Gp=E.ABSEnabled local Tp=false local Mp=tick()local Kp=false local Ip=false a.DriveSeat.ChildRemoved:connect(function(n)if n.Name=="\083\101\097\116\087\101\108\100"and n:IsA("\087\101\108\100")then script.Parent:Destroy()end end)local yp=E.Controls local wp=Instance.new("\070\111\108\100\101\114",script.Parent)wp.Name="\067\111\110\116\114\111\108\115"for n,F in pairs(yp)do local C=Instance.new("\083\116\114\105\110\103\086\097\108\117\101",wp)C.Name=n C.Value=F.Name C.Changed:connect(function()if n=="\077\111\117\115\101\084\104\114\111\116\116\108\101"or n=="\077\111\117\115\101\066\114\097\107\101"then if C.Value=="\077\111\117\115\101\066\117\116\116\111\110\049"or C.Value=="\077\111\117\115\101\066\117\116\116\111\110\050"then yp[n]=Enum.UserInputType[C.Value]else yp[n]=Enum.KeyCode[C.Value]end else yp[n]=Enum.KeyCode[C.Value]end end)end local up=E.Peripherals for n,F in pairs(up)do local C=Instance.new("\073\110\116\086\097\108\117\101",wp)C.Name=n C.Value=F C.Changed:connect(function()C.Value=math.min(100,math.max(0,C.Value))up[n]=C.Value end)end function DealWithInput(n,F)if C:GetFocusedTextBox()==nil and not Ip then if(n.KeyCode==yp.ContlrShiftDown or lp and n.KeyCode==yp.MouseShiftDown or not lp and n.KeyCode==yp.ShiftDown)and((I and((Ep=="\065\117\116\111"and X<=1)and E.AutoShiftVers=="\078\101\119")or Ep=="\083\101\109\105"or Ep=="\077\097\110\117\097\108")and n.UserInputState==Enum.UserInputState.Begin)then if not z then z=true end elseif(n.KeyCode==yp.ContlrShiftUp or lp and n.KeyCode==yp.MouseShiftUp or not lp and n.KeyCode==yp.ShiftUp)and((I and((Ep=="\065\117\116\111"and X<1)and E.AutoShiftVers=="\078\101\119")or Ep=="\083\101\109\105"or Ep=="\077\097\110\117\097\108")and n.UserInputState==Enum.UserInputState.Begin)then if not e then e=true end elseif(n.KeyCode==yp.ContlrClutch or lp and n.KeyCode==yp.MouseClutch or not lp and n.KeyCode==yp.Clutch)and Ep=="\077\097\110\117\097\108"then if n.UserInputState==Enum.UserInputState.Begin then c=true B=true elseif n.UserInputState==Enum.UserInputState.End then c=false B=false end elseif n.KeyCode==yp.ContlrPBrake or lp and n.KeyCode==yp.MousePBrake or not lp and n.KeyCode==yp.PBrake then if n.UserInputState==Enum.UserInputState.Begin then fp=not fp elseif n.UserInputState==Enum.UserInputState.End then if a.DriveSeat.Velocity.Magnitude>5 then fp=false end end elseif(n.KeyCode==yp.ContlrToggleTMode or n.KeyCode==yp.ToggleTransMode)and n.UserInputState==Enum.UserInputState.Begin then local n=1 for F,C in pairs(E.TransModes)do if C==Ep then n=F break end end n=n+1 if n>#E.TransModes then n=1 end Ep=E.TransModes[n]elseif not lp and(n.KeyCode==yp.Throttle or n.KeyCode==yp.Throttle2)or((yp.MouseThrottle==Enum.UserInputType.MouseButton1 or yp.MouseThrottle==Enum.UserInputType.MouseButton2)and n.UserInputType==yp.MouseThrottle or n.KeyCode==yp.MouseThrottle)and lp then if n.UserInputState==Enum.UserInputState.Begin and I then v=1 a.DriveSeat.Throttle=1 else a.DriveSeat.Throttle=0 v=E.IdleThrottle/100 end elseif not lp and(n.KeyCode==yp.Brake or n.KeyCode==yp.Brake2)or((yp.MouseBrake==Enum.UserInputType.MouseButton1 or yp.MouseBrake==Enum.UserInputType.MouseButton2)and n.UserInputType==yp.MouseBrake or n.KeyCode==yp.MouseBrake)and lp then if n.UserInputState==Enum.UserInputState.Begin then a.DriveSeat.Throttle=-1 U=1 else a.DriveSeat.Throttle=0 U=0 end elseif not lp and(n.KeyCode==yp.SteerLeft or n.KeyCode==yp.SteerLeft2)then if n.UserInputState==Enum.UserInputState.Begin then a.DriveSeat.Steer=-1 y=-1 Op=true else if ip then a.DriveSeat.Steer=1 y=1 else y=0 end a.DriveSeat.Steer=0 Op=false end elseif not lp and(n.KeyCode==yp.SteerRight or n.KeyCode==yp.SteerRight2)then if n.UserInputState==Enum.UserInputState.Begin then y=1 a.DriveSeat.Steer=1 ip=true else if Op then a.DriveSeat.Steer=-1 y=-1 else a.DriveSeat.Steer=0 y=0 end ip=false end elseif n.KeyCode==yp.ToggleMouseDrive then if n.UserInputState==Enum.UserInputState.End then lp=not lp v=E.IdleThrottle/100 U=0 y=0 end elseif E.TCSEnabled and(I and n.KeyCode==yp.ToggleTCS)or n.KeyCode==yp.ContlrToggleTCS then if n.UserInputState==Enum.UserInputState.End then Ap=not Ap end elseif E.ABSEnabled and(I and n.KeyCode==yp.ToggleABS)or n.KeyCode==yp.ContlrToggleABS then if n.UserInputState==Enum.UserInputState.End then Gp=not Gp end end if n.UserInputType.Name:find("\071\097\109\101\112\097\100")then if n.KeyCode==yp.ContlrSteer then if n.Position.X>=0 then local F=math.min(.99,E.Peripherals.ControlRDZone/100)if math.abs(n.Position.X)>F then y=(n.Position.X-F)/(1-F)else y=0 end else local F=math.min(.99,E.Peripherals.ControlLDZone/100)if math.abs(n.Position.X)>F then y=(n.Position.X+F)/(1-F)else y=0 end end elseif n.KeyCode==yp.ContlrThrottle then if I then v=math.max(E.IdleThrottle/100,n.Position.Z)else v=E.IdleThrottle/100 end elseif n.KeyCode==yp.ContlrBrake then U=n.Position.Z end end else v=E.IdleThrottle/100 y=0 U=0 end end C.InputBegan:connect(DealWithInput)C.InputChanged:connect(DealWithInput)C.InputEnded:connect(DealWithInput)if C.TouchEnabled then local n=script.Parent:WaitForChild("\066\117\116\116\111\110\115")local F=n:WaitForChild("\076\101\102\116")local C=n:WaitForChild("\082\105\103\104\116")local l=n:WaitForChild("\066\114\097\107\101")local O=n:WaitForChild("\071\097\115")local i=n.Downshift local f=n.Upshift local A=n:WaitForChild("\072\097\110\100\098\114\097\107\101")script.Parent.TextLabel.Visible=true local g=coroutine.wrap(function()while true do wait(.5)if Ep=="\083\101\109\105"or Ep=="\077\097\110\117\097\108"then i.Visible=true f.Visible=true else i.Visible=false f.Visible=false end end end)g()n.Visible=true local function p(n,F)if n.UserInputState==Enum.UserInputState.Begin then y=-1 a.DriveSeat.Steer=-1 Op=true else if ip then a.DriveSeat.Steer=1 y=1 else a.DriveSeat.Steer=0 y=0 end Op=false end end F.InputBegan:Connect(p)F.InputEnded:Connect(p)script.Parent.TextLabel.Visible=true local function G(n,F)if n.UserInputState==Enum.UserInputState.Begin then y=1 a.DriveSeat.Steer=1 ip=true else if Op then a.DriveSeat.Steer=-1 y=-1 else a.DriveSeat.Steer=0 y=0 end ip=false end end C.InputBegan:Connect(G)C.InputEnded:Connect(G)local function T(n,F)if n.UserInputState==Enum.UserInputState.Begin and I then a.DriveSeat.Throttle=1 v=1 else a.DriveSeat.Throttle=0 v=E.IdleThrottle/100 end end O.InputBegan:Connect(T)O.InputEnded:Connect(T)local function M(n,F)if n.UserInputState==Enum.UserInputState.Begin then a.DriveSeat.Throttle=-1 U=1 else U=0 a.DriveSeat.Throttle=0 end end l.InputBegan:Connect(M)l.InputEnded:Connect(M)script.Parent.TextLabel.Visible=true local function K(n,F)if n.UserInputState==Enum.UserInputState.Begin then fp=not fp elseif n.UserInputState==Enum.UserInputState.End then if a.DriveSeat.Velocity.Magnitude>5 then fp=false end end end A.InputBegan:Connect(K)A.InputEnded:Connect(K)local function w(n,F)if(I and((Ep=="\065\117\116\111"and X<=1)and E.AutoShiftVers=="\078\101\119")or Ep=="\083\101\109\105"or Ep=="\077\097\110\117\097\108")and n.UserInputState==Enum.UserInputState.Begin then if not z then z=true end end end i.InputBegan:Connect(w)local function u(n,F)if(I and((Ep=="\065\117\116\111"and X<1)and E.AutoShiftVers=="\078\101\119")or Ep=="\083\101\109\105"or Ep=="\077\097\110\117\097\108")and n.UserInputState==Enum.UserInputState.Begin then if not e then e=true end end end f.InputBegan:Connect(u)end local Dp={}script.Parent.TextLabel.Visible=true if E.Config=="\070\087\068"or E.Config=="\065\087\068"then for n,F in pairs(a.Wheels:GetChildren())do if F.Name=="\070\076"or F.Name=="\070\082"or F.Name=="\070"then table.insert(Dp,F)end end end if E.Config=="\082\087\068"or E.Config=="\065\087\068"then for n,F in pairs(a.Wheels:GetChildren())do if F.Name=="\082\076"or F.Name=="\082\082"or F.Name=="\082"then table.insert(Dp,F)end end end local vp=0 for n,F in pairs(Dp)do if F.Size.x>vp then vp=F.Size.x end end for n,F in pairs(a.Wheels:GetChildren())do if math.abs(F["\035\066\086"].MotorMaxTorque-A)<1 or math.abs(F["\035\066\086"].MotorMaxTorque-g)<1 then fp=true end end function Inputs(n)local F=60/(1/n)if D<=v then D=math.min(v,D+E.ThrotAccel*F)else D=math.max(v,D-E.ThrotDecel*F)end if L<=U then L=math.min(U,L+E.BrakeAccel*F)else L=math.max(U,L-E.BrakeDecel*F)end end if E.SteeringType=="\078\101\119"then G=(E.LockToLock*180)/E.SteerRatio T=math.min(G-G*(1-E.Ackerman),G*1.2)end function Steering(n)local C=60/(1/n)if lp then local n=math.max(1,(F.ViewSizeX*E.Peripherals.MSteerWidth)/200)local C=E.Peripherals.MSteerDZone/100 local a=(F.X-F.ViewSizeX/2)/n if math.abs(a)<=C then y=0 else y=(math.max(math.min(math.abs(a)-C,1-C),0)/(1-C))^E.MSteerExp*(a/math.abs(a))end end if w<y then if w<0 then w=math.min(y,w+E.ReturnSpeed*C)else w=math.min(y,w+E.SteerSpeed*C)end else if w>0 then w=math.max(y,w-E.ReturnSpeed*C)else w=math.max(y,w-E.SteerSpeed*C)end end local l=1-math.min(a.DriveSeat.Velocity.Magnitude/E.SteerDecay,1-E.MinSteer/100)local O=1-math.min(a.DriveSeat.Velocity.Magnitude/E.RSteerDecay,1-E.MinSteer/100)for n,F in pairs(a.Wheels:GetChildren())do if F.Name=="\070"then F.Arm.Steer.CFrame=a.Wheels.F.Base.CFrame*CFrame.Angles(0,-math.rad((w*E.SteerInner)*l),0)elseif F.Name=="\070\076"then if w>=0 then F.Arm.Steer.CFrame=a.Wheels.FL.Base.CFrame*CFrame.Angles(0,-math.rad((w*G)*l),0)else F.Arm.Steer.CFrame=a.Wheels.FL.Base.CFrame*CFrame.Angles(0,-math.rad((w*T)*l),0)end elseif F.Name=="\070\082"then if w>=0 then F.Arm.Steer.CFrame=a.Wheels.FR.Base.CFrame*CFrame.Angles(0,-math.rad((w*T)*l),0)else F.Arm.Steer.CFrame=a.Wheels.FR.Base.CFrame*CFrame.Angles(0,-math.rad((w*G)*l),0)end elseif F.Name=="\082"then if E.FWSteer=="\078\111\110\101"then elseif E.FWSteer=="\083\116\097\116\105\099"then F.Arm.Steer.CFrame=a.Wheels.R.Base.CFrame*CFrame.Angles(0,math.rad(((w*K)*O)*math.max(0,1-a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)elseif E.FWSteer=="\083\112\101\101\100"then F.Arm.Steer.CFrame=a.Wheels.R.Base.CFrame*CFrame.Angles(0,-math.rad(((w*K)*O)*math.min(1,a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)elseif E.FWSteer=="\066\111\116\104"then F.Arm.Steer.CFrame=a.Wheels.R.Base.CFrame*CFrame.Angles(0,math.rad(((w*K)*O)*math.max(-1,1-a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)end elseif F.Name=="\082\076"then if E.FWSteer=="\078\111\110\101"then elseif E.FWSteer=="\083\116\097\116\105\099"then if w>=0 then F.Arm.Steer.CFrame=a.Wheels.RL.Base.CFrame*CFrame.Angles(0,math.rad(((w*M)*O)*math.max(0,1-a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)else F.Arm.Steer.CFrame=a.Wheels.RL.Base.CFrame*CFrame.Angles(0,math.rad(((w*K)*O)*math.max(0,1-a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)end elseif E.FWSteer=="\083\112\101\101\100"then if w>=0 then F.Arm.Steer.CFrame=a.Wheels.RL.Base.CFrame*CFrame.Angles(0,-math.rad(((w*M)*O)*math.min(1,a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)else F.Arm.Steer.CFrame=a.Wheels.RL.Base.CFrame*CFrame.Angles(0,-math.rad(((w*K)*O)*math.min(1,a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)end elseif E.FWSteer=="\066\111\116\104"then if w>=0 then F.Arm.Steer.CFrame=a.Wheels.RL.Base.CFrame*CFrame.Angles(0,math.rad(((w*M)*O)*math.max(-1,1-a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)else F.Arm.Steer.CFrame=a.Wheels.RL.Base.CFrame*CFrame.Angles(0,math.rad(((w*K)*O)*math.max(-1,1-a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)end end elseif F.Name=="\082\082"then if E.FWSteer=="\078\111\110\101"then elseif E.FWSteer=="\083\116\097\116\105\099"then if w>=0 then F.Arm.Steer.CFrame=a.Wheels.RR.Base.CFrame*CFrame.Angles(0,math.rad(((w*K)*O)*math.max(0,1-a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)else F.Arm.Steer.CFrame=a.Wheels.RR.Base.CFrame*CFrame.Angles(0,math.rad(((w*M)*O)*math.max(0,1-a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)end elseif E.FWSteer=="\083\112\101\101\100"then if w>=0 then F.Arm.Steer.CFrame=a.Wheels.RR.Base.CFrame*CFrame.Angles(0,-math.rad(((w*K)*O)*math.min(1,a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)else F.Arm.Steer.CFrame=a.Wheels.RR.Base.CFrame*CFrame.Angles(0,-math.rad(((w*M)*O)*math.min(1,a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)end elseif E.FWSteer=="\066\111\116\104"then if w>=0 then F.Arm.Steer.CFrame=a.Wheels.RR.Base.CFrame*CFrame.Angles(0,math.rad(((w*K)*O)*math.max(-1,1-a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)else F.Arm.Steer.CFrame=a.Wheels.RR.Base.CFrame*CFrame.Angles(0,math.rad(((w*M)*O)*math.max(-1,1-a.DriveSeat.Velocity.Magnitude/E.RSteerSpeed)),0)end end end end end local qp=E.FinalDrive*E.FDMult local Lp=(qp*30)/math.pi local Up=(workspace.Gravity*E.InclineComp)/32.2 local cp=(vp*math.pi)/60 local Bp=CFrame.Angles(math.pi/2,-math.pi/2,0)local jp=CFrame.Angles(0,math.pi,0)if not E.Engine and E.Electric then E.Redline=E.E_Redline E.PeakRPM=E.E_Trans2 E.Turbochargers=0 E.Superchargers=0 E.Clutch=false E.IdleRPM=0 E.ClutchType="\067\108\117\116\099\104"E.AutoShiftType="\068\067\084"E.ShiftUpTime=.1 E.ShiftDnTime=.1 end Z=E.Turbochargers d=E.T_Boost*E.Turbochargers J=E.Superchargers m=E.S_Boost*E.Superchargers local kp=E.Horsepower/100 local Wp=(((E.Horsepower*(d*(E.T_Efficiency/10)))/7.5)/2)/100 local sp=(((E.Horsepower*(m*(E.S_Efficiency/10)))/7.5)/2)/100 local Np=E.PeakRPM/1000 local Vp=E.PeakSharpness local Xp=E.CurveMult local Yp=E.EqPoint/1000 function CurveN(n)n=n/1000 return(-(n-Np)^2*math.min(kp/Np^2,Xp^(Np/kp))+kp)*(n-n^Vp/(Vp*Np^(Vp-1)))end local ep=CurveN(E.PeakRPM)function CurveT(n)n=n/1000 return(-(n-Np)^2*math.min(Wp/Np^2,Xp^(Np/Wp))+Wp)*(n-n^Vp/(Vp*Np^(Vp-1)))end local zp=CurveT(E.PeakRPM)function CurveS(n)n=n/1000 return(-(n-Np)^2*math.min(sp/Np^2,Xp^(Np/sp))+sp)*(n-n^Vp/(Vp*Np^(Vp-1)))end local hp=CurveS(E.PeakRPM)local Pp=E.E_Horsepower/100 local rp=E.E_Torque/100 local Zp=E.E_Trans1/1000 local dp=E.E_Trans2/1000 local Qp=E.E_Redline/1000 function elecHP(n)n=n/1000 local F=1e-09 if n<=Zp then F=((n/Zp)^E.EH_FrontMult/(1/Pp))*(n/Zp)+((n/Zp)^(1/E.EH_FrontMult)/(1/Pp))*(1-n/Zp)elseif Zp<n and n<dp then F=Pp elseif dp<=n then F=Pp-((n-dp)/(Qp-dp))^E.EH_EndMult/(1/(Pp*(E.EH_EndPercent/100)))else error("\n\t \091\065\067\054\067\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 "..(n..("\044 \084\049\058 "..(Zp("\044 \084\050\058 ")..(dp("\044 \076\058 ")..Qp("\046")))))))))end return F end function elecTQ(n)n=n/1000 local F=1e-09 if n<Zp then F=rp elseif Zp<=n then F=rp-((n-Zp)/(Qp-Zp))^E.ET_EndMult/(1/(rp*(E.ET_EndPercent/100)))else error("\n\t \091\065\067\054\067\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 "..(n..("\044 \084\049\058 "..(Zp("\044 \084\050\058 ")..(dp("\044 \076\058 ")..Qp("\046")))))))))end return F end function GetNCurve(n,F)local C=math.max(CurveN(n)/(ep/kp),0)*100 return C,((((C*(Yp/n))*E.Ratios[F+2])*qp)*O)*1000 end function GetECurve(n,F)local C=math.max(elecHP(n),0)*100 local a=math.max(elecTQ(n),0)*100 if F~=0 then return C,math.max(((a*E.Ratios[F+2])*qp)*O,0)else return 0,0 end end function GetTCurve(n,F)local C=math.max(CurveT(n)/(zp/Wp),0)*100 return C,((((C*(Yp/n))*E.Ratios[F+2])*qp)*O)*1000 end function GetSCurve(n,F)local C=math.max(CurveS(n)/(hp/sp),0)*100 return C,((((C*(Yp/n))*E.Ratios[F+2])*qp)*O)*1000 end local Jp={}local mp={}local tp={}local op={}for n,F in pairs(E.Ratios)do local C={}local a={}local l={}local O={}for F=0,math.ceil((E.Redline+100)/100),1 do local i={}local f={}local A={}local g={}if F~=0 then if E.Engine then i.Horsepower,i.Torque=GetNCurve(F*100,n-2)if Z~=0 then A.Horsepower,A.Torque=GetTCurve(F*100,n-2)else A.Horsepower,A.Torque=0,0 end if J~=0 then g.Horsepower,g.Torque=GetSCurve(F*100,n-2)else g.Horsepower,g.Torque=0,0 end else i.Horsepower,i.Torque=0,0 A.Horsepower,A.Torque=0,0 g.Horsepower,g.Torque=0,0 end if E.Electric then f.Horsepower,f.Torque=GetECurve(F*100,n-2)else f.Horsepower,f.Torque=0,0 end else i.Horsepower,i.Torque=0,0 f.Horsepower,f.Torque=0,0 A.Horsepower,A.Torque=0,0 g.Horsepower,g.Torque=0,0 end if E.Engine then nhp,ntq=GetNCurve((F+1)*100,n-2)if Z~=0 then thp,ttq=GetTCurve((F+1)*100,n-2)else thp,ttq=0,0 end if J~=0 then shp,stq=GetSCurve((F+1)*100,n-2)else shp,stq=0,0 end else nhp,ntq=0,0 thp,ttq=0,0 shp,stq=0,0 end if E.Electric then ehp,etq=GetECurve((F+1)*100,n-2)else ehp,etq=0,0 end i.HpSlope,i.TqSlope=nhp-i.Horsepower,ntq-i.Torque f.HpSlope,f.TqSlope=ehp-f.Horsepower,etq-f.Torque A.HpSlope,A.TqSlope=thp-A.Horsepower,ttq-A.Torque g.HpSlope,g.TqSlope=shp-g.Horsepower,stq-g.Torque C[F]=i a[F]=f l[F]=A O[F]=g end table.insert(Jp,C)table.insert(mp,a)table.insert(tp,l)table.insert(op,O)end wait()function Auto()local n=0 for F,C in pairs(Dp)do if C.RotVelocity.Magnitude>n then n=C.RotVelocity.Magnitude end end if I then if E.AutoShiftVers=="\079\108\100"and X==0 then X=1 c=false end if X>=1 then if(X==1 and(L>0 and a.DriveSeat.Velocity.Magnitude<5))and E.AutoShiftVers=="\079\108\100"then X=-1 c=false elseif a.DriveSeat.Velocity.Magnitude>5 then if E.AutoShiftMode=="\082\080\077"then if s>E.PeakRPM+E.AutoUpThresh then if not e and not h then e=true end elseif math.max(math.min((n*E.Ratios[X+1])*Lp,E.Redline+100),E.IdleRPM)<E.PeakRPM-E.AutoDownThresh and X>1 then if not z and not h then z=true end end else if a.DriveSeat.Velocity.Magnitude>math.ceil(((cp*(E.PeakRPM+E.AutoUpThresh))/E.Ratios[X+2])/qp)then if not e and not h then e=true end elseif a.DriveSeat.Velocity.Magnitude<math.ceil(((cp*(E.PeakRPM-E.AutoDownThresh))/E.Ratios[X+1])/qp)and X>1 then if not z and not h then z=true end end end end else if(D-E.IdleThrottle/100>0 and a.DriveSeat.Velocity.Magnitude<5)and E.AutoShiftVers=="\079\108\100"then X=1 c=false end end end end function Gear()local n=0 for F,C in pairs(Dp)do if C.RotVelocity.Magnitude>n then n=C.RotVelocity.Magnitude end end if e and not h then if Ep=="\077\097\110\117\097\108"and not c or Ep=="\077\097\110\117\097\108"and(E.ClutchRel and D-E.IdleThrottle/100>0)or X==#E.Ratios-2 or Ep~="\077\097\110\117\097\108"and not I then e=false return end local F=math.min(X+3,#E.Ratios)if Ep~="\077\097\110\117\097\108"then h=true if X>0 then if E.AutoShiftType=="\068\067\084"then wait(E.ShiftUpTime)elseif E.AutoShiftType=="\082\101\118"then repeat wait()until s<=math.max(math.min((n*E.Ratios[F])*Lp,E.Redline-E.RevBounce),E.IdleRPM)or not I or z end end end e=false h=false if Ep~="\077\097\110\117\097\108"and not I then return end X=math.min(X+1,#E.Ratios-2)if Ep~="\077\097\110\117\097\108"or(Ep=="\077\097\110\117\097\108"and X==1)and I then c=false end end if z and not h then if Ep=="\077\097\110\117\097\108"and not c or X==-1 or Ep~="\077\097\110\117\097\108"and not I then z=false return end local F=math.min(X+1,#E.Ratios)if Ep~="\077\097\110\117\097\108"then h=true if X>1 then if E.AutoShiftType=="\068\067\084"then wait(E.ShiftDnTime)elseif E.AutoShiftType=="\082\101\118"then repeat wait()until s>=math.max(math.min((n*E.Ratios[F])*Lp,E.Redline-E.RevBounce),E.IdleRPM)or not I or e end end end z=false h=false if Ep~="\077\097\110\117\097\108"and not I then return end X=math.max(X-1,-1)if Ep~="\077\097\110\117\097\108"or(Ep=="\077\097\110\117\097\108"and X==-1)and I then c=false end end end local Sp=0 local xp=1 local Rp=0 local Hp=false local bp=tick()function Engine(n)local F=60/(1/n)if(X==0 or h)and I then c=true j=1 Hp=false end local C=E.IdleRPM local l=E.IdleRPM local O=E.Redline if E.Stall and E.Clutch then C=0 end if h and e then u=0 elseif h and z then u=E.ShiftThrot/100 else if E.AutoShiftVers=="\079\108\100"and(X==-1 and Ep=="\065\117\116\111")then u=L else u=D end end if E.AutoShiftVers=="\079\108\100"and(X==-1 and Ep=="\065\117\116\111")then q=D-E.IdleThrottle/100 else q=L end if not I then bp=tick()C=0 l=0 u=E.IdleThrottle/100 if Ep~="\077\097\110\117\097\108"then X=0 c=true j=1 end end if(c and X==0 or B and X~=0)and E.NeutralLimit then if X==0 and not E.LimitClutch or E.LimitClutch then O=E.NeutralRevRPM end end local G=0 local T=0 local M=u for n,F in pairs(Dp)do G=G+F.RotVelocity.Magnitude T=T+1 end G=G/T if Sp>O+100 then M=E.IdleThrottle/100 end if E.Engine or E.Electric then Sp=math.clamp((s-E.RevDecay*F)+((E.RevDecay+E.RevAccel)*M)*F,l,E.Redline+100)end if Sp>E.Redline then if X<#E.Ratios-2 then Sp=Sp-E.RevBounce else Sp=Sp-E.RevBounce*.5 end end local K=(G*E.Ratios[X+2])*Lp if E.Clutch then if script.Parent.Values.AutoClutch.Value and I then if E.ClutchType=="\067\108\117\116\099\104"then if c then k=1 end k=k*(E.ClutchEngage/100)local n=math.max(((s-E.IdleRPM)*E.ClutchRPMMult)/(E.Redline-E.IdleRPM),0)if E.ClutchMode=="\078\101\119"then n=0 end W=math.min(((script.Parent.Values.Velocity.Value.Magnitude/E.SpeedEngage)/math.abs(X)+n)-k,1)elseif E.ClutchType=="\067\086\084"or E.ClutchType=="\084\111\114\113\117\101\067\111\110\118\101\114\116\101\114"and E.TQLock then if u-E.IdleThrottle/100==0 and script.Parent.Values.Velocity.Value.Magnitude<E.SpeedEngage or u-E.IdleThrottle/100~=0 and(s<E.RPMEngage and K<E.RPMEngage)then W=math.min(W*(E.ClutchEngage/100),1)else W=math.min(W*(E.ClutchEngage/100)+(1-E.ClutchEngage/100),1)end elseif E.ClutchType=="\084\111\114\113\117\101\067\111\110\118\101\114\116\101\114"and not E.TQLock then W=math.min((s/E.Redline)*.7,1)end if not c then j=math.min(1-W,1)else j=1 end Hp=j<=.01 or Hp else Hp=E.Stall j=script.Parent.Values.Clutch.Value end else Hp=false if not c and not h then j=0 else j=1 end end local y=math.max(math.min(Sp*j+K*(1-j),E.Redline+100),C)local w=math.min(math.abs(y-s)/(E.Flywheel*F),.9)if c then w=0 end s=s*w+y*(1-w)if s<=E.IdleRPM/4 and(Hp and tick()-bp>=.2)then script.Parent.IsOn.Value=not E.Stall end P=(E.Redline+100)/(Lp*E.Ratios[X+2])if s>E.Redline then if X<#E.Ratios-2 then s=s-E.RevBounce else s=s-E.RevBounce*.5 end end local v=d/Z local U=u if E.Engine then if Z~=0 then Q=Q+(((((N*(U*1.2))/E.Horsepower)/8-(Q/v)*(v/15))*((8/(E.T_Size/F))*2))/v)*15 if Q<.05 then Q=.05 elseif Q>2 then Q=2 end else Q=0 end if J~=0 then if U>Rp then Rp=math.min(U,Rp+E.S_Sensitivity*F)elseif U<Rp then Rp=math.max(U,Rp-E.S_Sensitivity*F)end t=(s/E.Redline)*(.5+1.5*Rp)else t=0 end else Q=0 t=0 end if E.Engine then local n=Jp[X+2][math.floor(math.min(E.Redline,math.max(0,s))/100)]o=n.Horsepower+n.HpSlope*(((s-math.floor(s/100))/100)%1)S=n.Torque+n.TqSlope*(((s-math.floor(s/100))/100)%1)if Z~=0 then local n=tp[X+2][math.floor(math.min(E.Redline,math.max(0,s))/100)]H=(n.Horsepower+n.HpSlope*(((s-math.floor(s/100))/100)%1))*(Q/2)b=(n.Torque+n.TqSlope*(((s-math.floor(s/100))/100)%1))*(Q/2)else H,b=0,0 end if J~=0 then local n=op[X+2][math.floor(math.min(E.Redline,math.max(0,s))/100)]np=(n.Horsepower+n.HpSlope*(((s-math.floor(s/100))/100)%1))*(t/2)Fp=(n.Torque+n.TqSlope*(((s-math.floor(s/100))/100)%1))*(t/2)else np,Fp=0,0 end Cp=H+np ap=b+Fp else o,S=0,0 H,b=0,0 np,Fp=0,0 Cp,ap=0,0 end if E.Electric and X~=0 then local n=mp[X+2][math.floor(math.min(E.Redline,math.max(100,s))/100)]x=n.Horsepower+n.HpSlope*(((s-math.floor(s/100))/100)%1)R=n.Torque+n.TqSlope*(((s-math.floor(s/100))/100)%1)else x,R=0,0 end N=(o+Cp)+x V=(S+ap)+R local Y=a.DriveSeat.CFrame.lookVector.y*Up if X==-1 then Y=-Y end V=V*math.max(1,1+Y)local r=0 local m=0 local lp=0 local Op=0 for n,F in pairs(a.Wheels:GetChildren())do if F.Name=="\070\076"or F.Name=="\070\082"or F.Name=="\070"then r=r+F.RotVelocity.Magnitude m=m+1 elseif F.Name=="\082\076"or F.Name=="\082\082"or F.Name=="\082"then lp=lp+F.RotVelocity.Magnitude Op=Op+1 end end r=r/m lp=lp/Op local ip=(r+lp)/2 for n,F in pairs(a.Wheels:GetChildren())do local C=(CFrame.new(F.Position-(F.Arm.CFrame*Bp).lookVector,F.Position)*jp).lookVector local l=1 local O=1 local G=1 local T=1 local M=1 local K=1 if F.Name=="\070\076"or F.Name=="\082\076"then l=-1 end if E.DifferentialType=="\079\108\100"then if F.Name=="\070\076"or F.Name=="\070\082"then O=math.max(0,math.min(1,1+(((F.RotVelocity.Magnitude-r)/r)/(math.max(E.FDiffSlipThres,1)/100))*((E.FDiffLockThres-50)/50)))if E.Config=="\065\087\068"then O=math.max(0,math.min(1,O*(1+(((r-ip)/ip)/(math.max(E.CDiffSlipThres,1)/100))*((E.CDiffLockThres-50)/50))))end elseif F.Name=="\082\076"or F.Name=="\082\082"then O=math.max(0,math.min(1,1+(((F.RotVelocity.Magnitude-lp)/lp)/(math.max(E.RDiffSlipThres,1)/100))*((E.RDiffLockThres-50)/50)))if E.Config=="\065\087\068"then O=math.max(0,math.min(1,O*(1+(((lp-ip)/ip)/(math.max(E.CDiffSlipThres,1)/100))*((E.CDiffLockThres-50)/50))))end end else if F.Name=="\070\082"then local n=(F.RotVelocity.Magnitude/a.Wheels.FL.RotVelocity.Magnitude-1)*(E.FDiffPreload/10)M=math.ceil(math.max(0,math.min(2,1-(((E.FDiffPower/100)*n)*u+((E.FDiffCoast/100)*n)*(1-u))))*100)/100 K=2-M elseif F.Name=="\070\076"then local n=(F.RotVelocity.Magnitude/a.Wheels.FR.RotVelocity.Magnitude-1)*(E.FDiffPreload/10)K=math.ceil(math.max(0,math.min(2,1-(((E.FDiffPower/100)*n)*u+((E.FDiffCoast/100)*n)*(1-u))))*100)/100 M=2-K elseif F.Name=="\082\082"then local n=(F.RotVelocity.Magnitude/a.Wheels.RL.RotVelocity.Magnitude-1)*(E.RDiffPreload/10)G=math.ceil(math.max(0,math.min(2,1-(((E.RDiffPower/100)*n)*u+((E.RDiffCoast/100)*n)*(1-u))))*100)/100 T=2-G elseif F.Name=="\082\076"then local n=(F.RotVelocity.Magnitude/a.Wheels.RR.RotVelocity.Magnitude-1)*(E.RDiffPreload/10)T=math.ceil(math.max(0,math.min(2,1-(((E.RDiffPower/100)*n)*u+((E.RDiffCoast/100)*n)*(1-u))))*100)/100 G=2-T end end gp=false Tp=false local I=1 if not script.Parent.IsOn.Value then I=0 end local y=u local w=q local D=1 if c then D=0 end local v=V local L=1 if Gp and(w>0 and math.abs(F.RotVelocity.Magnitude*(F.Size.x/2)-F.Velocity.Magnitude)-E.ABSThreshold>0)then L=0 end Tp=L<1 local U=0 if fp==true then U=1 else U=0 end local B=false for n,C in pairs(Dp)do if C==F then B=true end end if B then if E.Config=="\065\087\068"then local n=(E.TorqueVector+1)/2 if string.find(F.Name,"\070")then v=v*(1-n)elseif string.find(F.Name,"\082")then v=v*n end end xp=1 if Ap and y>0 then xp=1-math.min(math.max(0,math.abs(F.RotVelocity.Magnitude*(F.Size.x/2)-F.Velocity.Magnitude)-E.TCSThreshold)/E.TCSGradient,1)*(1-E.TCSLimit/100)end if xp<1 then pp=xp gp=true end local n=1 if X==-1 then n=-1 end if E.ClutchKick and(a.DriveSeat.Velocity.Magnitude<E.KickSpeedThreshold and(s>E.Redline-E.KickRPMThreshold and F["\035\066\086"].MotorMaxTorque<1))then v=v*E.KickMult end local C=(((((v*(60/workspace:GetRealPhysicsFPS()))*(1+(F.RotVelocity.Magnitude/(120-workspace:GetRealPhysicsFPS()))^(1.15+.07*(1-60/workspace:GetRealPhysicsFPS()))))*y)*xp)*I)*D if F.Name=="\082\082"then F["\035\065\086"].MotorMaxTorque=(C*G)*O elseif F.Name=="\082\076"then F["\035\065\086"].MotorMaxTorque=(C*T)*O elseif F.Name=="\070\082"then F["\035\065\086"].MotorMaxTorque=(C*M)*O elseif F.Name=="\070\076"then F["\035\065\086"].MotorMaxTorque=(C*K)*O else F["\035\065\086"].MotorMaxTorque=C*O end F["\035\065\086"].AngularVelocity=P*n if string.find(F.Name,"\070")then F["\035\066\086"].MotorMaxTorque=(((i*(60/workspace:GetRealPhysicsFPS()))*w)*L+p*((1-y)*(s/E.Redline)))+A*U else F["\035\066\086"].MotorMaxTorque=(((f*(60/workspace:GetRealPhysicsFPS()))*w)*L+p*((1-y)*(s/E.Redline)))+g*U end else F["\035\065\086"].MotorMaxTorque=0 F["\035\065\086"].AngularVelocity=0 if string.find(F.Name,"\070")then F["\035\066\086"].MotorMaxTorque=((i*(60/workspace:GetRealPhysicsFPS()))*w)*L+A*U else F["\035\066\086"].MotorMaxTorque=((f*(60/workspace:GetRealPhysicsFPS()))*w)*L+g*U end end end end function Flip()if(a.DriveSeat.CFrame*CFrame.Angles(math.pi/2,0,0)).lookVector.y>.1 or Kp then Mp=tick()else if tick()-Mp>=3 then Kp=true local n=a.DriveSeat.Flip n.maxTorque=Vector3.new(10000,0,10000)n.P=3000 n.D=500 wait(1)n.maxTorque=Vector3.new(0,0,0)n.P=0 n.D=0 Kp=false end end end local nt=require(a["\065-\067\104\097\115\115\105\115 \084\117\110\101"].README)print("\078\111\118\101\110\097\058 \065\067\054\067 \076\111\097\100\101\100 - \086\101\114\115\105\111\110 "..(nt..("\044 \085\112\100\097\116\101 "..script.Parent.Version.Value)))game["\082\117\110 \083\101\114\118\105\099\101"].Heartbeat:connect(function(n)I=script.Parent.IsOn.Value Ip=script.Parent.ControlsOpen.Value Inputs(n)Steering(n)Gear()Engine(n)script.Parent.Values.Gear.Value=X script.Parent.Values.RPM.Value=s script.Parent.Values.Boost.Value=(Q/2)*d+(t/2)*m script.Parent.Values.BoostTurbo.Value=(Q/2)*d script.Parent.Values.BoostSuper.Value=(t/2)*m script.Parent.Values.HpNatural.Value=o script.Parent.Values.HpElectric.Value=x script.Parent.Values.HpTurbo.Value=H script.Parent.Values.HpSuper.Value=np script.Parent.Values.HpBoosted.Value=Cp script.Parent.Values.Horsepower.Value=N script.Parent.Values.TqNatural.Value=((S/E.Ratios[X+2])/qp)/O script.Parent.Values.TqElectric.Value=((R/E.Ratios[X+2])/qp)/O script.Parent.Values.TqTurbo.Value=((b/E.Ratios[X+2])/qp)/O script.Parent.Values.TqSuper.Value=((Fp/E.Ratios[X+2])/qp)/O script.Parent.Values.TqBoosted.Value=script.Parent.Values.TqTurbo.Value+script.Parent.Values.TqSuper.Value script.Parent.Values.Torque.Value=(script.Parent.Values.TqNatural.Value+script.Parent.Values.TqElectric.Value)+script.Parent.Values.TqBoosted.Value script.Parent.Values.TransmissionMode.Value=Ep script.Parent.Values.Throttle.Value=u script.Parent.Values.Brake.Value=q if script.Parent.Values.AutoClutch.Value then script.Parent.Values.Clutch.Value=j end script.Parent.Values.SteerC.Value=w script.Parent.Values.SteerT.Value=y script.Parent.Values.PBrake.Value=fp script.Parent.Values.TCS.Value=Ap script.Parent.Values.TCSActive.Value=gp script.Parent.Values.TCSAmt.Value=1-pp script.Parent.Values.ABS.Value=Gp script.Parent.Values.ABSActive.Value=Tp script.Parent.Values.MouseSteerOn.Value=lp script.Parent.Values.Velocity.Value=a.DriveSeat.Velocity end)while wait(.0667)do if Ep=="\065\117\116\111"then Auto()end if E.AutoFlip then Flip()end end
--
	
	--[[START]]
	
script.Parent:WaitForChild("Car")
script.Parent:WaitForChild("IsOn")
script.Parent:WaitForChild("ControlsOpen")
script.Parent:WaitForChild("Values")
	
	--[[Dependencies]]
	
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local UserInputService = game:GetService("UserInputService")
local car = script.Parent.Car.Value
local _Tune = require(car["A-Chassis Tune"])
local _text1 = script.Parent.Version:WaitForChild("TextLabel")
_text1.Parent = script.Parent
	
	--[[Output Scaling Factor]]
	
local hpScaling = _Tune.WeightScaling * 10
local FBrakeForce = _Tune.BrakeForce * _Tune.BrakeBias--luaint edit
local RBrakeForce = _Tune.BrakeForce * (1 - _Tune.BrakeBias)--luaint edit
local PBrakeForceF = _Tune.PBrakeForce * _Tune.PBrakeBias
local PBrakeForceR = _Tune.PBrakeForce * (1 - _Tune.PBrakeBias)
local EBrakeForce = _Tune.EBrakeForce
local SteerOuter  = _Tune.SteerOuter--luaint edit
local SteerInner  = _Tune.SteerInner--luaint edit
local RSteerOuter = _Tune.RSteerOuter
local RSteerInner = _Tune.RSteerInner


if not workspace:PGSIsEnabled() then
	error("PGS is not enabled: A-Chassis will not work.")
end
	
	--[[Status Vars]]
	
local _IsOn = _Tune.AutoStart
if _Tune.AutoStart and (_Tune.Engine or _Tune.Electric) then
	script.Parent.IsOn.Value = true
end
	
local _GSteerT = 0
local _GSteerC = 0
local _GThrot = 0
local _InThrot = 0
local _IThrot = _Tune.IdleThrottle / 100
local _GBrake = 0
local _InBrake = 0
local _IBrake = 0
	
local _ClPressing = false
local _PlayerClutch = false
local _Clutch = 0
local _ClutchKick = 0
local _ClutchModulate = 0
local _RPM = 0
local _HP = 0
local _OutTorque = 0
local _CGear = 0
local _PGear = _CGear
local _ShiftUp = false
local _ShiftDn = false
local _Shifting = false
local _spLimit = 0
	
local _Boost = 0
local _TCount = 0
local _TPsi = 0
local _TBoost = 0
local _SCount = 0
local _SPsi = 0
local _SBoost = 0
local _NH = 0
local _NT = 0
local _EH = 0
local _ET = 0
local _TH = 0
local _TT = 0
local _SH = 0
local _ST = 0
local _BH = 0
local _BT = 0
	
local _TMode = _Tune.TransModes[1]
	
local _MSteer = false
local _SteerL = false
local _SteerR = false
local _PBrake = false
local _TCS = _Tune.TCSEnabled
local _TCSActive = false
local _TCSAmt = 0
local _ABS = _Tune.ABSEnabled
local _ABSActive = false
	
local FlipWait = tick()
local FlipDB = false
	
local _InControls = false
	
	
	--[[Shutdown]]
	
car.DriveSeat.ChildRemoved:connect(function(child)
	if child.Name == "SeatWeld" and child:IsA("Weld") then
		script.Parent:Destroy()
	end
end)
	
	--[[Controls]]
	
local _CTRL = _Tune.Controls
local Controls = Instance.new("Folder", script.Parent)
Controls.Name = "Controls"
for i, v in pairs(_CTRL) do
	local a = Instance.new("StringValue", Controls)
	a.Name = i
	a.Value = v.Name
	a.Changed:connect(function()
		if i == "MouseThrottle" or i == "MouseBrake" then
			if a.Value == "MouseButton1" or a.Value == "MouseButton2" then
				_CTRL[i] = Enum.UserInputType[a.Value]
			else
				_CTRL[i] = Enum.KeyCode[a.Value]
			end
		else
			_CTRL[i] = Enum.KeyCode[a.Value]
		end
	end)
end
	
	--Deadzone Adjust
local _PPH = _Tune.Peripherals
for i, v in pairs(_PPH) do
	local a = Instance.new("IntValue", Controls)
	a.Name = i
	a.Value = v
	a.Changed:connect(function() 
		a.Value = math.min(100, math.max(0, a.Value))
		_PPH[i] = a.Value
	end)
end
	
	--Input Handler
function DealWithInput(input, IsRobloxFunction)
	if (UserInputService:GetFocusedTextBox() == nil) and not _InControls then --Ignore when UI Focus
			--Shift Down [Manual Transmission]
		if (input.KeyCode == _CTRL["ContlrShiftDown"] or (_MSteer and input.KeyCode == _CTRL["MouseShiftDown"]) or ((not _MSteer) and input.KeyCode == _CTRL["ShiftDown"])) and ((_IsOn and ((_TMode == "Auto" and _CGear <= 1) and _Tune.AutoShiftVers == "New") or _TMode == "Semi") or _TMode == "Manual") and input.UserInputState == Enum.UserInputState.Begin then
			if not _ShiftDn then
				_ShiftDn = true
			end
				
			--Shift Up [Manual Transmission]
		elseif (input.KeyCode == _CTRL["ContlrShiftUp"] or (_MSteer and input.KeyCode == _CTRL["MouseShiftUp"]) or ((not _MSteer) and input.KeyCode == _CTRL["ShiftUp"])) and ((_IsOn and ((_TMode == "Auto" and _CGear < 1) and _Tune.AutoShiftVers == "New") or _TMode == "Semi") or _TMode == "Manual") and input.UserInputState == Enum.UserInputState.Begin then
			if not _ShiftUp then
				_ShiftUp = true
			end
				
			--Toggle Clutch
		elseif (input.KeyCode == _CTRL["ContlrClutch"] or (_MSteer and input.KeyCode == _CTRL["MouseClutch"]) or ((not _MSteer) and input.KeyCode == _CTRL["Clutch"])) and _TMode == "Manual" then
			if input.UserInputState == Enum.UserInputState.Begin then
				_ClPressing = true
				_PlayerClutch = true
			elseif input.UserInputState == Enum.UserInputState.End then
				_ClPressing = false
				_PlayerClutch = false
			end
				
			--Toggle PBrake
		elseif input.KeyCode == _CTRL["ContlrPBrake"] or (_MSteer and input.KeyCode == _CTRL["MousePBrake"]) or ((not _MSteer) and input.KeyCode == _CTRL["PBrake"]) then
			if input.UserInputState == Enum.UserInputState.Begin then
				_PBrake = not _PBrake
			elseif input.UserInputState == Enum.UserInputState.End then
				if car.DriveSeat.Velocity.Magnitude > 5 then
					_PBrake = false
				end
			end
				
			--Toggle Transmission Mode
		elseif (input.KeyCode == _CTRL["ContlrToggleTMode"] or input.KeyCode == _CTRL["ToggleTransMode"]) and input.UserInputState == Enum.UserInputState.Begin then
			local n = 1
			for i, v in pairs(_Tune.TransModes) do
				if v == _TMode then
					n = i
					break
				end
			end
			n = n + 1
			if n > #_Tune.TransModes then
				n = 1
			end
			_TMode = _Tune.TransModes[n]
				
			--Throttle
		elseif ((not _MSteer) and (input.KeyCode == _CTRL["Throttle"] or input.KeyCode == _CTRL["Throttle2"])) or ((((_CTRL["MouseThrottle"] == Enum.UserInputType.MouseButton1 or _CTRL["MouseThrottle"] == Enum.UserInputType.MouseButton2) and input.UserInputType == _CTRL["MouseThrottle"]) or input.KeyCode == _CTRL["MouseThrottle"]) and _MSteer) then
			if input.UserInputState == Enum.UserInputState.Begin and _IsOn then
				_IThrot = 1
				car.DriveSeat.Throttle = 1
			else
				car.DriveSeat.Throttle = 0
				_IThrot = _Tune.IdleThrottle / 100
			end
				
			--Brake
		elseif ((not _MSteer) and (input.KeyCode == _CTRL["Brake"] or input.KeyCode == _CTRL["Brake2"])) or ((((_CTRL["MouseBrake"] == Enum.UserInputType.MouseButton1 or _CTRL["MouseBrake"] == Enum.UserInputType.MouseButton2) and input.UserInputType == _CTRL["MouseBrake"]) or input.KeyCode == _CTRL["MouseBrake"]) and _MSteer) then
			if input.UserInputState == Enum.UserInputState.Begin then
				car.DriveSeat.Throttle = -1
				_IBrake = 1
			else
				car.DriveSeat.Throttle = 0
				_IBrake = 0
			end
				
			--Steer Left
		elseif (not _MSteer) and (input.KeyCode == _CTRL["SteerLeft"] or input.KeyCode == _CTRL["SteerLeft2"]) then
			if input.UserInputState == Enum.UserInputState.Begin then
				car.DriveSeat.Steer = -1
				_GSteerT = -1
				_SteerL = true
			else
				if _SteerR then
					car.DriveSeat.Steer = 1
					_GSteerT = 1
				else
					_GSteerT = 0
				end
				car.DriveSeat.Steer = 0
				_SteerL = false
			end
				
			--Steer Right
		elseif (not _MSteer) and (input.KeyCode == _CTRL["SteerRight"] or input.KeyCode == _CTRL["SteerRight2"]) then
			if input.UserInputState == Enum.UserInputState.Begin then
				_GSteerT = 1
				car.DriveSeat.Steer = 1
				_SteerR = true
			else
				if _SteerL then
					car.DriveSeat.Steer = -1
					_GSteerT = -1
				else
					car.DriveSeat.Steer = 0
					_GSteerT = 0
				end
				_SteerR = false
			end
				
			--Toggle Mouse Controls
		elseif input.KeyCode == _CTRL["ToggleMouseDrive"] then
			if input.UserInputState == Enum.UserInputState.End then
				_MSteer = not _MSteer
				_IThrot = _Tune.IdleThrottle / 100
				_IBrake = 0
				_GSteerT = 0
			end
				
			--Toggle TCS
		elseif _Tune.TCSEnabled and _IsOn and input.KeyCode == _CTRL["ToggleTCS"] or input.KeyCode == _CTRL["ContlrToggleTCS"] then
			if input.UserInputState == Enum.UserInputState.End then
				_TCS = not _TCS
			end
			
			--Toggle ABS
		elseif _Tune.ABSEnabled and _IsOn and input.KeyCode == _CTRL["ToggleABS"] or input.KeyCode == _CTRL["ContlrToggleABS"] then
			if input.UserInputState == Enum.UserInputState.End then
				_ABS = not _ABS
			end
				
		end
			
			--Variable Controls
		if input.UserInputType.Name:find("Gamepad") then
				--Gamepad Steering
			if input.KeyCode == _CTRL["ContlrSteer"] then
				if input.Position.X >= 0 then
					local cDZone = math.min(.99, _Tune.Peripherals.ControlRDZone / 100)
					if math.abs(input.Position.X) > cDZone then
						_GSteerT = (input.Position.X - cDZone) / (1 - cDZone)
					else
						_GSteerT = 0
					end
				else
					local cDZone = math.min(.99, _Tune.Peripherals.ControlLDZone / 100)
					if math.abs(input.Position.X) > cDZone then
						_GSteerT = (input.Position.X + cDZone) / (1 - cDZone)
					else
						_GSteerT = 0
					end
				end
					
				--Gamepad Throttle
			elseif input.KeyCode == _CTRL["ContlrThrottle"] then
				if _IsOn then
					_IThrot = math.max(_Tune.IdleThrottle / 100, input.Position.Z)
				else
					_IThrot = _Tune.IdleThrottle / 100
				end
					
				--Gamepad Brake
			elseif input.KeyCode == _CTRL["ContlrBrake"] then
				_IBrake = input.Position.Z
			end
		end
	else
		_IThrot = _Tune.IdleThrottle / 100
		_GSteerT = 0
		_IBrake = 0
	end
end
UserInputService.InputBegan:connect(DealWithInput)
UserInputService.InputChanged:connect(DealWithInput)
UserInputService.InputEnded:connect(DealWithInput)
	
	
	-- Eniiqz' Mobile Support Mod	
if UserInputService.TouchEnabled then
	local Buttons = script.Parent:WaitForChild("Buttons")
	local Left = Buttons:WaitForChild("Left")
	local Right = Buttons:WaitForChild("Right")
	local Brake = Buttons:WaitForChild("Brake")
	local Gas = Buttons:WaitForChild("Gas")
	local Downshift = Buttons.Downshift
	local Upshift = Buttons.Upshift
	local Handbrake = Buttons:WaitForChild("Handbrake")
	script.Parent.TextLabel.Visible = true
	local Thread = coroutine.wrap(function()
		while true do
			wait(0.5)
			if _TMode == "Semi" or _TMode == "Manual" then
				Downshift.Visible = true
				Upshift.Visible = true
			else
				Downshift.Visible = false
				Upshift.Visible = false
			end
		end
	end)
	Thread()
	Buttons.Visible = true
	
	local function LeftTurn(Touch, GPE)
		if Touch.UserInputState == Enum.UserInputState.Begin then
			_GSteerT = -1
			car.DriveSeat.Steer = -1
			_SteerL = true
		else
			if _SteerR then
				car.DriveSeat.Steer = 1
				_GSteerT = 1
			else
				car.DriveSeat.Steer = 0
				_GSteerT = 0
			end
			_SteerL = false
		end
	end
	Left.InputBegan:Connect(LeftTurn)
	Left.InputEnded:Connect(LeftTurn)
	--Left.InputChanged:Connect(LeftTurn)
	script.Parent.TextLabel.Visible = true
	local function RightTurn(Touch, GPE)
		if Touch.UserInputState == Enum.UserInputState.Begin then
			_GSteerT = 1
			car.DriveSeat.Steer = 1
			_SteerR = true
		else
			if _SteerL then
				car.DriveSeat.Steer = -1
				_GSteerT = -1
			else
				car.DriveSeat.Steer = 0
				_GSteerT = 0
			end
			_SteerR = false
		end
	end
	Right.InputBegan:Connect(RightTurn)
	Right.InputEnded:Connect(RightTurn)
	--Right.InputChanged:Connect(RightTurn)
	
	local function TouchThrottle(input, GPE)
		if input.UserInputState == Enum.UserInputState.Begin and _IsOn then
			car.DriveSeat.Throttle = 1
			_IThrot = 1
		else
			car.DriveSeat.Throttle = 0
			_IThrot = _Tune.IdleThrottle / 100
		end
	end
	Gas.InputBegan:Connect(TouchThrottle)
	Gas.InputEnded:Connect(TouchThrottle)
	--Gas.InputChanged:Connect(TouchThrottle)
	
	local function TouchBrake(input, GPE)
		if input.UserInputState == Enum.UserInputState.Begin then
			car.DriveSeat.Throttle = -1
			_IBrake = 1
		else
			
			_IBrake = 0
			car.DriveSeat.Throttle = 0
		end
	end
	Brake.InputBegan:Connect(TouchBrake)
	Brake.InputEnded:Connect(TouchBrake)
	--Brake.InputChanged:Connect(TouchBrake)
	script.Parent.TextLabel.Visible = true
	local function TouchHandbrake(input, GPE)
		if input.UserInputState == Enum.UserInputState.Begin then
			_PBrake = not _PBrake
		elseif input.UserInputState == Enum.UserInputState.End then
			if car.DriveSeat.Velocity.Magnitude > 5 then
				_PBrake = false
			end
		end
	end
	Handbrake.InputBegan:Connect(TouchHandbrake)
	Handbrake.InputEnded:Connect(TouchHandbrake)


	local function TouchDownshift(input, GPE)
		if ((_IsOn and ((_TMode == "Auto" and _CGear <= 1) and _Tune.AutoShiftVers == "New") or _TMode == "Semi") or _TMode == "Manual") and input.UserInputState == Enum.UserInputState.Begin then
			if not _ShiftDn then
				_ShiftDn = true
			end
		end
	end

	Downshift.InputBegan:Connect(TouchDownshift)

	local function TouchUpshift(input, GPE)
		if ((_IsOn and ((_TMode == "Auto" and _CGear < 1) and _Tune.AutoShiftVers == "New") or _TMode == "Semi") or _TMode == "Manual") and input.UserInputState == Enum.UserInputState.Begin then
			if not _ShiftUp then
				_ShiftUp = true
			end
		end
	end
	Upshift.InputBegan:Connect(TouchUpshift)
	
end -- MOBILE SUPPORT IF STATEMENT
	--[[Drivetrain Initialize]]
	
local Drive = {}
script.Parent.TextLabel.Visible = true
	--Power Front Wheels
if _Tune.Config == "FWD" or _Tune.Config == "AWD" then
	for i, v in pairs(car.Wheels:GetChildren()) do
		if v.Name == "FL" or v.Name == "FR" or v.Name == "F" then
			table.insert(Drive, v)
		end
	end
end
	
	--Power Rear Wheels
if _Tune.Config == "RWD" or _Tune.Config == "AWD" then
	for i, v in pairs(car.Wheels:GetChildren()) do
		if v.Name == "RL" or v.Name == "RR" or v.Name == "R" then
			table.insert(Drive, v)
		end
	end
end
	
	--Determine Wheel Size
local wDia = 0
for i, v in pairs(Drive) do
	if v.Size.x > wDia then
		wDia = v.Size.x
	end
end
	
	--Pre-Toggled PBrake
for i, v in pairs(car.Wheels:GetChildren()) do
	if (math.abs(v["#BV"].MotorMaxTorque - PBrakeForceF) < 1) or (math.abs(v["#BV"].MotorMaxTorque - PBrakeForceR) < 1) then
		_PBrake = true
	end
end
	
	--[[Throttle and Brake Input Smoothening]]
	
function Inputs(dt)
	local deltaTime = (60 / (1 / dt))
	if _InThrot <= _IThrot then
		_InThrot = math.min(_IThrot, _InThrot + (_Tune.ThrotAccel * deltaTime))
	else
		_InThrot = math.max(_IThrot, _InThrot - (_Tune.ThrotDecel * deltaTime))
	end
	if _InBrake <= _IBrake then
		_InBrake = math.min(_IBrake, _InBrake + (_Tune.BrakeAccel * deltaTime))
	else
		_InBrake = math.max(_IBrake, _InBrake - (_Tune.BrakeDecel * deltaTime))
	end
end
	
	--[[Steering]]
	
if _Tune.SteeringType == 'New' then--luaint edit
	SteerOuter = (_Tune.LockToLock * 180) / _Tune.SteerRatio
	SteerInner = math.min(SteerOuter - (SteerOuter * (1 - _Tune.Ackerman)), SteerOuter * 1.2)
end
	
function Steering(dt)
	local deltaTime = (60 / (1 / dt))
		--Mouse Steer
	if _MSteer then
		local msWidth = math.max(1, mouse.ViewSizeX * _Tune.Peripherals.MSteerWidth / 200)
		local mdZone = _Tune.Peripherals.MSteerDZone / 100
		local mST = ((mouse.X - mouse.ViewSizeX / 2) / msWidth)
		if math.abs(mST) <= mdZone then
			_GSteerT = 0
		else
			_GSteerT = (math.max(math.min((math.abs(mST) - mdZone), (1 - mdZone)), 0) / (1 - mdZone)) ^ _Tune.MSteerExp * (mST / math.abs(mST))
		end
	end
		
		--Interpolate Steering
	if _GSteerC < _GSteerT then
		if _GSteerC < 0 then
			_GSteerC = math.min(_GSteerT, _GSteerC + (_Tune.ReturnSpeed * deltaTime))
		else
			_GSteerC = math.min(_GSteerT, _GSteerC + (_Tune.SteerSpeed * deltaTime))
		end
	else
		if _GSteerC > 0 then
			_GSteerC = math.max(_GSteerT, _GSteerC - (_Tune.ReturnSpeed * deltaTime))
		else
			_GSteerC = math.max(_GSteerT, _GSteerC - (_Tune.SteerSpeed * deltaTime))
		end
	end
		
		--Steer Decay Multiplier
	local sDecay = (1 - math.min(car.DriveSeat.Velocity.Magnitude / _Tune.SteerDecay, 1 - (_Tune.MinSteer / 100)))
	local rsDecay = (1 - math.min(car.DriveSeat.Velocity.Magnitude / _Tune.RSteerDecay, 1 - (_Tune.MinSteer / 100)))
		
		--Apply Steering
	for i, v in pairs(car.Wheels:GetChildren()) do
		if v.Name == "F" then
			v.Arm.Steer.CFrame = car.Wheels.F.Base.CFrame * CFrame.Angles(0, -math.rad(_GSteerC * _Tune.SteerInner * sDecay), 0)
		elseif v.Name == "FL" then
			if _GSteerC >= 0 then
				v.Arm.Steer.CFrame = car.Wheels.FL.Base.CFrame * CFrame.Angles(0, -math.rad(_GSteerC * SteerOuter * sDecay), 0)--luaint edit
			else
				v.Arm.Steer.CFrame = car.Wheels.FL.Base.CFrame * CFrame.Angles(0, -math.rad(_GSteerC * SteerInner * sDecay), 0)--luaint edit
			end	
		elseif v.Name == "FR" then
			if _GSteerC >= 0 then
				v.Arm.Steer.CFrame = car.Wheels.FR.Base.CFrame * CFrame.Angles(0, -math.rad(_GSteerC * SteerInner * sDecay), 0)--luaint edit
			else
				v.Arm.Steer.CFrame = car.Wheels.FR.Base.CFrame * CFrame.Angles(0, -math.rad(_GSteerC * SteerOuter * sDecay), 0)--luaint edit
			end
		elseif v.Name == 'R' then
			if _Tune.FWSteer == 'None' then
			elseif _Tune.FWSteer == 'Static' then
				v.Arm.Steer.CFrame = car.Wheels.R.Base.CFrame * CFrame.Angles(0, math.rad(_GSteerC * RSteerInner * rsDecay * math.max(0, 1 - (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
			elseif _Tune.FWSteer == 'Speed' then
				v.Arm.Steer.CFrame = car.Wheels.R.Base.CFrame * CFrame.Angles(0, -math.rad(_GSteerC * RSteerInner * rsDecay * math.min(1, (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
			elseif _Tune.FWSteer == 'Both' then
				v.Arm.Steer.CFrame = car.Wheels.R.Base.CFrame * CFrame.Angles(0, math.rad(_GSteerC * RSteerInner * rsDecay * math.max(-1, 1 - (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
			end
		elseif v.Name == 'RL' then
			if _Tune.FWSteer == 'None' then
			elseif _Tune.FWSteer == 'Static' then
				if _GSteerC >= 0 then
					v.Arm.Steer.CFrame = car.Wheels.RL.Base.CFrame * CFrame.Angles(0, math.rad(_GSteerC * RSteerOuter * rsDecay * math.max(0, 1 - (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
				else
					v.Arm.Steer.CFrame = car.Wheels.RL.Base.CFrame * CFrame.Angles(0, math.rad(_GSteerC * RSteerInner * rsDecay * math.max(0, 1 - (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
				end
			elseif _Tune.FWSteer == 'Speed' then
				if _GSteerC >= 0 then
					v.Arm.Steer.CFrame = car.Wheels.RL.Base.CFrame * CFrame.Angles(0, -math.rad(_GSteerC * RSteerOuter * rsDecay * math.min(1, (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
				else
					v.Arm.Steer.CFrame = car.Wheels.RL.Base.CFrame * CFrame.Angles(0, -math.rad(_GSteerC * RSteerInner * rsDecay * math.min(1, (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
				end
			elseif _Tune.FWSteer == 'Both' then
				if _GSteerC >= 0 then
					v.Arm.Steer.CFrame = car.Wheels.RL.Base.CFrame * CFrame.Angles(0, math.rad(_GSteerC * RSteerOuter * rsDecay * math.max(-1, 1 - (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
				else
					v.Arm.Steer.CFrame = car.Wheels.RL.Base.CFrame * CFrame.Angles(0, math.rad(_GSteerC * RSteerInner * rsDecay * math.max(-1, 1 - (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
				end
			end
		elseif v.Name == 'RR' then
			if _Tune.FWSteer == 'None' then
			elseif _Tune.FWSteer == 'Static' then
				if _GSteerC >= 0 then
					v.Arm.Steer.CFrame = car.Wheels.RR.Base.CFrame * CFrame.Angles(0, math.rad(_GSteerC * RSteerInner * rsDecay * math.max(0, 1 - (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
				else
					v.Arm.Steer.CFrame = car.Wheels.RR.Base.CFrame * CFrame.Angles(0, math.rad(_GSteerC * RSteerOuter * rsDecay * math.max(0, 1 - (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
				end
			elseif _Tune.FWSteer == 'Speed' then
				if _GSteerC >= 0 then
					v.Arm.Steer.CFrame = car.Wheels.RR.Base.CFrame * CFrame.Angles(0, -math.rad(_GSteerC * RSteerInner * rsDecay * math.min(1, (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
				else
					v.Arm.Steer.CFrame = car.Wheels.RR.Base.CFrame * CFrame.Angles(0, -math.rad(_GSteerC * RSteerOuter * rsDecay * math.min(1, (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
				end
			elseif _Tune.FWSteer == 'Both' then
				if _GSteerC >= 0 then
					v.Arm.Steer.CFrame = car.Wheels.RR.Base.CFrame * CFrame.Angles(0, math.rad(_GSteerC * RSteerInner * rsDecay * math.max(-1, 1 - (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
				else
					v.Arm.Steer.CFrame = car.Wheels.RR.Base.CFrame * CFrame.Angles(0, math.rad(_GSteerC * RSteerOuter * rsDecay * math.max(-1, 1 - (car.DriveSeat.Velocity.Magnitude / _Tune.RSteerSpeed))), 0)--luaint edit
				end
			end
		end
	end
end
	
	
	
	--[[Engine]]
	
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)
	
	--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.ClutchType = "Clutch" 
	_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 = _Tune.Horsepower / 100
local HP_T = ((_Tune.Horsepower * ((_TPsi) * (_Tune.T_Efficiency / 10)) / 7.5) / 2) / 100
local HP_S = ((_Tune.Horsepower * ((_SPsi) * (_Tune.S_Efficiency / 10)) / 7.5) / 2) / 100
	
local Peak = _Tune.PeakRPM / 1000
local Sharpness = _Tune.PeakSharpness
local CurveMult = _Tune.CurveMult
local EQ = _Tune.EqPoint / 1000
	
function CurveN(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 PeakCurveN = CurveN(_Tune.PeakRPM)
	
function CurveT(RPM)
	RPM = RPM / 1000
	return ((-(RPM - Peak) ^ 2) * math.min(HP_T / (Peak ^ 2), CurveMult ^ (Peak / HP_T)) + HP_T) * (RPM - ((RPM ^ Sharpness) / (Sharpness * Peak ^ (Sharpness - 1))))
end
local PeakCurveT = CurveT(_Tune.PeakRPM)
	
function CurveS(RPM)
	RPM = RPM / 1000
	return ((-(RPM - Peak) ^ 2) * math.min(HP_S / (Peak ^ 2), CurveMult ^ (Peak / HP_S)) + HP_S) * (RPM - ((RPM ^ Sharpness) / (Sharpness * Peak ^ (Sharpness - 1))))
end
local PeakCurveS = CurveS(_Tune.PeakRPM)
	
	--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 [AC6C]: 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 [AC6C]: 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 Naturally Aspirated Engine Horsepower
function GetNCurve(x, gear)
	local hp = (math.max(CurveN(x) / (PeakCurveN / HP), 0)) * 100
	return hp, ((hp * (EQ / x)) * _Tune.Ratios[gear + 2] * fFD * hpScaling) * 1000
end
	
	--Plot Current Electric Horsepower
function GetECurve(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 + 2] * fFD * hpScaling, 0)
	else
		return 0, 0
	end
end
	
	--Plot Current Turbocharger Horsepower 
function GetTCurve(x, gear)
	local hp = (math.max(CurveT(x) / (PeakCurveT / HP_T), 0)) * 100
	return hp, ((hp * (EQ / x)) * _Tune.Ratios[gear + 2] * fFD * hpScaling) * 1000
end	
	
	--Plot Current Supercharger Horsepower 
function GetSCurve(x, gear)
	local hp = (math.max(CurveS(x) / (PeakCurveS / HP_S), 0)) * 100
	return hp, ((hp * (EQ / x)) * _Tune.Ratios[gear + 2] * fFD * hpScaling) * 1000
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 = GetNCurve(rpm * 100, gear - 2)
				if _TCount ~= 0 then
					ttqPlot.Horsepower, ttqPlot.Torque = GetTCurve(rpm * 100, gear - 2)
				else
					ttqPlot.Horsepower, ttqPlot.Torque = 0, 0
				end
				if _SCount ~= 0 then
					stqPlot.Horsepower, stqPlot.Torque = GetSCurve(rpm * 100, gear - 2)
				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 = GetECurve(rpm * 100, gear - 2)
			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 = GetNCurve((rpm + 1) * 100, gear - 2)
			if _TCount ~= 0 then
				thp, ttq = GetTCurve((rpm + 1) * 100, gear - 2)
			else
				thp, ttq = 0, 0
			end
			if _SCount ~= 0 then
				shp, stq = GetSCurve((rpm + 1) * 100, gear - 2)
			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 = GetECurve((rpm + 1) * 100, gear - 2)
		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()
	
	--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
		if _Tune.AutoShiftVers == "Old" and _CGear == 0 then
			_CGear = 1
			_ClPressing = false
		end
		if _CGear >= 1 then
			if (_CGear == 1 and _InBrake > 0 and car.DriveSeat.Velocity.Magnitude < 5) and _Tune.AutoShiftVers == "Old" then
				_CGear = -1
				_ClPressing = false
			elseif car.DriveSeat.Velocity.Magnitude > 5 then
				if _Tune.AutoShiftMode == "RPM" 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 car.DriveSeat.Velocity.Magnitude > math.ceil(wDRatio * (_Tune.PeakRPM + _Tune.AutoUpThresh) / _Tune.Ratios[_CGear + 2] / fFD) then
						if not _ShiftUp and not _Shifting then
							_ShiftUp = true
						end
					elseif car.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 car.DriveSeat.Velocity.Magnitude < 5) and _Tune.AutoShiftVers == "Old" then
				_CGear = 1
				_ClPressing = false
			end
		end
	end 
end
	
function Gear()
	local maxSpin = 0
	for i, v in pairs(Drive) do
		if v.RotVelocity.Magnitude > maxSpin then
			maxSpin = v.RotVelocity.Magnitude
		end
	end
	if _ShiftUp and not _Shifting then
		if (_TMode == "Manual" and not _ClPressing) or (_TMode == "Manual" and _Tune.ClutchRel and (_InThrot - (_Tune.IdleThrottle / 100) > 0)) or _CGear == #_Tune.Ratios - 2 or (_TMode ~= "Manual" and not _IsOn) then
			_ShiftUp = false
			return
		end
		local NextGear = math.min(_CGear + 3, #_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 - 2)
		if _TMode ~= "Manual" or (_TMode == "Manual" and _CGear == 1) and _IsOn then
			_ClPressing = false
		end
	end
	if _ShiftDn and not _Shifting then
		if (_TMode == "Manual" and not _ClPressing) or _CGear == -1 or (_TMode ~= "Manual" and not _IsOn) then
			_ShiftDn = false
			return
		end
		local PrevGear = math.min(_CGear + 1, #_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, -1)
		if _TMode ~= "Manual" or (_TMode == "Manual" and _CGear == -1) and _IsOn then
			_ClPressing = false
		end
	end
end
	
local _GoalRPM = 0
local tqTCS = 1
local sthrot = 0
local _StallOK = false
local ticc = tick()
	--Apply Power
function Engine(dt)
	local deltaTime = (60 / (1 / dt))
		--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 
	local goalMax = _Tune.Redline
	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
		if (_Tune.AutoShiftVers == "Old" and _CGear == -1 and _TMode == "Auto") then
			_GThrot = _InBrake
		else
			_GThrot = _InThrot
		end
	end
		
	if (_Tune.AutoShiftVers == "Old" and _CGear == -1 and _TMode == "Auto") then
		_GBrake = _InThrot - (_Tune.IdleThrottle / 100)
	else
		_GBrake = _InBrake
	end
		
	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
		
	if ((_ClPressing and _CGear == 0) or (_PlayerClutch and _CGear ~= 0)) and _Tune.NeutralLimit then
		if (_CGear == 0 and not _Tune.LimitClutch) or _Tune.LimitClutch then
			goalMax = _Tune.NeutralRevRPM
		end
	end
		
		--Determine RPM
	local maxSpin = 0
	local maxCount = 0
	local revThrot = _GThrot
	for i, v in pairs(Drive) do
		maxSpin = maxSpin + v.RotVelocity.Magnitude
		maxCount = maxCount + 1
	end
	maxSpin = maxSpin / maxCount
		
	if _GoalRPM > goalMax + 100 then 
		revThrot = _Tune.IdleThrottle / 100
	end
		
	if _Tune.Engine or _Tune.Electric then
		_GoalRPM = math.clamp((_RPM - _Tune.RevDecay * deltaTime) + ((_Tune.RevDecay + _Tune.RevAccel) * revThrot * deltaTime), goalMin, _Tune.Redline + 100)
	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 + 2] * fFDr
		
	if _Tune.Clutch then
		if script.Parent.Values.AutoClutch.Value and _IsOn then
			if _Tune.ClutchType == "Clutch" then
				if _ClPressing 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 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 _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 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 + 2])
	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 + 2][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 + 2][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 + 2][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 + 2][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
		
	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
		local RRdiffMult = 1
		local RLdiffMult = 1
		local FRdiffMult = 1
		local FLdiffMult = 1
		if v.Name == "FL" or v.Name == "RL" then
			aRef = -1
		end
			
			--Differential/Torque-Vectoring
		if _Tune.DifferentialType == 'Old' then
			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
		else
			if v.Name == "FR" then
				local avg = ((v.RotVelocity.Magnitude / car.Wheels.FL.RotVelocity.Magnitude) - 1) * (_Tune.FDiffPreload / 10)
				FRdiffMult = math.ceil(math.max(0, math.min(2, 1 - ( ((_Tune.FDiffPower / 100) * avg * _GThrot) + ((_Tune.FDiffCoast / 100) * avg * (1 - _GThrot))))) * 100) / 100
				FLdiffMult = 2 - FRdiffMult
			elseif v.Name == "FL" then
				local avg = ((v.RotVelocity.Magnitude / car.Wheels.FR.RotVelocity.Magnitude) - 1) * (_Tune.FDiffPreload / 10)
				FLdiffMult = math.ceil(math.max(0, math.min(2, 1 - ( ((_Tune.FDiffPower / 100) * avg * _GThrot) + ((_Tune.FDiffCoast / 100) * avg * (1 - _GThrot))))) * 100) / 100
				FRdiffMult = 2 - FLdiffMult
			elseif v.Name == "RR" then
				local avg = ((v.RotVelocity.Magnitude / car.Wheels.RL.RotVelocity.Magnitude) - 1) * (_Tune.RDiffPreload / 10)
				RRdiffMult = math.ceil(math.max(0, math.min(2, 1 - ( ((_Tune.RDiffPower / 100) * avg * _GThrot) + ((_Tune.RDiffCoast / 100) * avg * (1 - _GThrot))))) * 100) / 100
				RLdiffMult = 2 - RRdiffMult
			elseif v.Name == "RL" then
				local avg = ((v.RotVelocity.Magnitude / car.Wheels.RR.RotVelocity.Magnitude) - 1) * (_Tune.RDiffPreload / 10)
				RLdiffMult = math.ceil(math.max(0, math.min(2, 1 - ( ((_Tune.RDiffPower / 100) * avg * _GThrot) + ((_Tune.RDiffCoast / 100) * avg * (1 - _GThrot))))) * 100) / 100
				RRdiffMult = 2 - RLdiffMult
			end
		end
			
		_TCSActive = false
		_ABSActive = false
			--Output
		
			--Apply Power
		local on = 1
		if not script.Parent.IsOn.Value then
			on = 0
		end
		local throt = _GThrot
		local brake = _GBrake
		local clutch = 1
		if _ClPressing then
			clutch = 0
		end
		local tq = _OutTorque
			
			--Apply ABS
		local tqABS = 1
		if _ABS and brake > 0 and math.abs(v.RotVelocity.Magnitude * (v.Size.x / 2) - v.Velocity.Magnitude) - _Tune.ABSThreshold > 0 then
			tqABS = 0
		end
		_ABSActive = (tqABS < 1)
		
		local PBrakeV = 0
		if _PBrake == true then
			PBrakeV = 1
		else
			PBrakeV = 0
		end
			
		local driven = false
		for _, a in pairs(Drive) do
			if a == v then
				driven = true
			end
		end
		if driven then
				--Apply AWD Vectoring
			if _Tune.Config == "AWD" then
				local bias = (_Tune.TorqueVector + 1) / 2
				if string.find(v.Name, "F") then
					tq = tq * (1 - bias)
				elseif string.find(v.Name, "R") then
					tq = tq * bias
				end
			end
				
				--Apply TCS
			tqTCS = 1
			if _TCS and throt > 0 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--luaint edit
				
			if _Tune.ClutchKick and car.DriveSeat.Velocity.Magnitude < _Tune.KickSpeedThreshold and _RPM > _Tune.Redline - _Tune.KickRPMThreshold and v["#BV"].MotorMaxTorque < 1 then 
				tq = (tq * _Tune.KickMult)
			end
				
			local tqOUT = tq * (60 / workspace:GetRealPhysicsFPS()) * (1 + (v.RotVelocity.Magnitude / (120 - workspace:GetRealPhysicsFPS())) ^ (1.15 + (.07 * (1 - (60 / workspace:GetRealPhysicsFPS()))))) * throt * tqTCS * on * clutch
				
			if v.Name == 'RR' then
				v["#AV"].MotorMaxTorque = tqOUT * RRdiffMult * diffMult
			elseif v.Name == 'RL' then
				v["#AV"].MotorMaxTorque = tqOUT * RLdiffMult * diffMult
			elseif v.Name == 'FR' then
				v["#AV"].MotorMaxTorque = tqOUT * FRdiffMult * diffMult
			elseif v.Name == 'FL' then
				v["#AV"].MotorMaxTorque = tqOUT * FLdiffMult * diffMult
			else
				v["#AV"].MotorMaxTorque = tqOUT * diffMult
			end
			v["#AV"].AngularVelocity = _spLimit * dir
			
			if string.find(v.Name, "F") then
				v["#BV"].MotorMaxTorque = (FBrakeForce * (60 / workspace:GetRealPhysicsFPS()) * brake * tqABS) + (EBrakeForce * ((1 - throt) * (_RPM / _Tune.Redline))) + (PBrakeForceF * PBrakeV)
			else
				v["#BV"].MotorMaxTorque = (RBrakeForce * (60 / workspace:GetRealPhysicsFPS()) * brake * tqABS) + (EBrakeForce * ((1 - throt) * (_RPM / _Tune.Redline))) + (PBrakeForceR * PBrakeV)
			end
		else--luaint edit
			v["#AV"].MotorMaxTorque = 0
			v["#AV"].AngularVelocity = 0
			if string.find(v.Name, "F") then
				v["#BV"].MotorMaxTorque = (FBrakeForce * (60 / workspace:GetRealPhysicsFPS()) * brake * tqABS) + (PBrakeForceF * PBrakeV)
			else
				v["#BV"].MotorMaxTorque = (RBrakeForce * (60 / workspace:GetRealPhysicsFPS()) * brake * tqABS) + (PBrakeForceR * PBrakeV)
			end
		end
	end
end
	
	
	
	--[[Flip]]
	
function Flip()
		--Detect Orientation
	if (car.DriveSeat.CFrame * CFrame.Angles(math.pi / 2, 0, 0)).lookVector.y > .1 or FlipDB then
		FlipWait = tick()
			
		--Apply Flip
	else
		if tick() - FlipWait >= 3 then
			FlipDB = true
			local gyro = car.DriveSeat.Flip
			gyro.maxTorque = Vector3.new(10000, 0, 10000)
			gyro.P = 3000
			gyro.D = 500
			wait(1)
			gyro.maxTorque = Vector3.new(0, 0, 0)
			gyro.P = 0
			gyro.D = 0
			FlipDB = false
		end
	end
end
	
	
	--[[Run]]
	
	--Print Version
local ver = require(car["A-Chassis Tune"].README)
print("Novena: AC6C Loaded - Version "..ver..", Update "..script.Parent.Version.Value)
	
	--Runtime Loops
	
	-- ~60 c/s
game["Run Service"].Heartbeat:connect(function(dt)
		--Update Internal Values
	_IsOn = script.Parent.IsOn.Value
	_InControls = script.Parent.ControlsOpen.Value
		
		--Inputs
	Inputs(dt)
		
		--Steering
	Steering(dt)
		
		--Gear
	Gear()
		
		--Power
	Engine(dt)
		
		--Update External Values
	script.Parent.Values.Gear.Value = _CGear
	script.Parent.Values.RPM.Value = _RPM
	script.Parent.Values.Boost.Value = ((_TBoost / 2) * _TPsi) + ((_SBoost / 2) * _SPsi)
	script.Parent.Values.BoostTurbo.Value = (_TBoost / 2) * _TPsi
	script.Parent.Values.BoostSuper.Value = (_SBoost / 2) * _SPsi
	script.Parent.Values.HpNatural.Value = _NH
	script.Parent.Values.HpElectric.Value = _EH
	script.Parent.Values.HpTurbo.Value = _TH
	script.Parent.Values.HpSuper.Value = _SH
	script.Parent.Values.HpBoosted.Value = _BH
	script.Parent.Values.Horsepower.Value = _HP
	script.Parent.Values.TqNatural.Value = _NT / _Tune.Ratios[_CGear + 2] / fFD / hpScaling
	script.Parent.Values.TqElectric.Value = _ET / _Tune.Ratios[_CGear + 2] / fFD / hpScaling
	script.Parent.Values.TqTurbo.Value = _TT / _Tune.Ratios[_CGear + 2] / fFD / hpScaling
	script.Parent.Values.TqSuper.Value = _ST / _Tune.Ratios[_CGear + 2] / fFD / hpScaling
	script.Parent.Values.TqBoosted.Value = script.Parent.Values.TqTurbo.Value + script.Parent.Values.TqSuper.Value
	script.Parent.Values.Torque.Value = script.Parent.Values.TqNatural.Value + script.Parent.Values.TqElectric.Value + script.Parent.Values.TqBoosted.Value
	script.Parent.Values.TransmissionMode.Value = _TMode
	script.Parent.Values.Throttle.Value = _GThrot
	script.Parent.Values.Brake.Value = _GBrake
	if script.Parent.Values.AutoClutch.Value then
		script.Parent.Values.Clutch.Value = _Clutch
	end
	script.Parent.Values.SteerC.Value = _GSteerC
	script.Parent.Values.SteerT.Value = _GSteerT
	script.Parent.Values.PBrake.Value = _PBrake
	script.Parent.Values.TCS.Value = _TCS
	script.Parent.Values.TCSActive.Value = _TCSActive
	script.Parent.Values.TCSAmt.Value = 1 - _TCSAmt
	script.Parent.Values.ABS.Value = _ABS
	script.Parent.Values.ABSActive.Value = _ABSActive
	script.Parent.Values.MouseSteerOn.Value = _MSteer
	script.Parent.Values.Velocity.Value = car.DriveSeat.Velocity
end)
	
	--15 c/s
while wait(.0667) do
		--Automatic Transmission
	if _TMode == "Auto" then
		Auto()
	end
		
		--Flip
	if _Tune.AutoFlip then
		Flip()
	end
end
