local U=script.Parent.Car.Value local Z=script.Parent.Values local f=require(U["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local Q=U:WaitForChild("\073\078\084\069\082\073\079\082\095\080\065\067\075")local K=workspace.FilteringEnabled local G=nil for U,Z in pairs(U.Misc:GetDescendants())do if Z:IsA("\079\098\106\101\099\116\086\097\108\117\101")and Z.Name=="\073\078\084\069\082\073\079\082\095\080\065\067\075"then G=Z.Value end end if G==nil then script:Destroy()end local w=G:FindFirstChild("\072\097\110\100\098\114\097\107\101")local r=G:FindFirstChild("\080\097\100\100\108\101\095\083\104\105\102\116\101\114")local F=G:FindFirstChild("\080\101\100\097\108\115")local c=G:FindFirstChild("\083\104\105\102\116\101\114")local N=G:FindFirstChild("\083\116\101\101\114\105\110\103\095\087\104\101\101\108")local D=0 local p=1 if SEQ_INVERTED then p=-1 end local E=1 if PED_INVERTED then E=-1 end local I=Z.Gear.Changed:Connect(function()local U=Z.Gear.Value local G="\068\111\119\110"if U>D then G="\085\112"end D=U if K then Q:FireServer("\071\101\097\114",U,G,PADDLE_SHIFTER,PEDALS,SHIFTER,r,F,c,PADDLE_ANG,PADDLE_INVERTED,SHIFTER_TYPE,p,SHIFT_TIME,VERTICAL_ANG,HORIZONTAL_ANG)else if PEDALS and F~=nil then F.C.Motor.DesiredAngle=math.rad(PEDAL_ANGLE)*E end if PADDLE_SHIFTER and r~=nil then if G=="\085\112"then if PADDLE_INVERTED then r.L.Motor.DesiredAngle=math.rad(PADDLE_ANG)else r.R.Motor.DesiredAngle=math.rad(PADDLE_ANG)end else if PADDLE_INVERTED then r.R.Motor.DesiredAngle=math.rad(PADDLE_ANG)else r.L.Motor.DesiredAngle=math.rad(PADDLE_ANG)end end wait(SHIFT_TIME/2)r.R.Motor.DesiredAngle=0 r.L.Motor.DesiredAngle=0 end if SHIFTER and c~=nil then local Z=c.W1.Motor local Q=c.W2.Motor Q.DesiredAngle=0 wait(SHIFT_TIME/2)if SHIFTER_TYPE=="\083\101\113"then if G=="\085\112"then Q.DesiredAngle=math.rad(VERTICAL_ANG)*p wait(SHIFT_TIME/2)Q.DesiredAngle=0 else Q.DesiredAngle=-math.rad(VERTICAL_ANG)*p wait(SHIFT_TIME/2)Q.DesiredAngle=0 end else if U==-1 then Z.DesiredAngle=(math.floor((#f.Ratios-1)/4)*2)*math.rad(HORIZONTAL_ANG)wait(SHIFT_TIME/2)if#f.Ratios%2==0 then Q.DesiredAngle=math.rad(VERTICAL_ANG)else Q.DesiredAngle=-math.rad(VERTICAL_ANG)end elseif U==0 then Z.DesiredAngle=0 elseif U>0 then if G=="\085\112"then if D==0 then Z.DesiredAngle=-math.floor((#f.Ratios-1)/4)*math.rad(HORIZONTAL_ANG)wait(SHIFT_TIME/2)Q.DesiredAngle=math.rad(VERTICAL_ANG)elseif U%2==0 then Q.DesiredAngle=-math.rad(VERTICAL_ANG)else Z.DesiredAngle=Z.DesiredAngle+math.rad(HORIZONTAL_ANG)wait(SHIFT_TIME/2)Q.DesiredAngle=math.rad(VERTICAL_ANG)end else if U%2==0 then Z.DesiredAngle=Z.DesiredAngle-math.rad(HORIZONTAL_ANG)wait(SHIFT_TIME/2)Q.DesiredAngle=-math.rad(VERTICAL_ANG)else Q.DesiredAngle=math.rad(VERTICAL_ANG)end end end end end if PEDALS and F~=nil then F.C.Motor.DesiredAngle=0 end end end)local n=Z.Throttle.Changed:Connect(function()local U=Z.Throttle.Value if K then Q:FireServer("\084\104\114\111\116\116\108\101",U,PEDALS,F,PEDAL_ANGLE,E)else if PEDALS and F~=nil then F.T.Motor.DesiredAngle=math.rad(PEDAL_ANGLE*U)*E end end end)local i=Z.Brake.Changed:Connect(function()local U=Z.Brake.Value if K then Q:FireServer("\066\114\097\107\101",U,PEDALS,F,PEDAL_ANGLE,E)else if PEDALS and F~=nil then F.B.Motor.DesiredAngle=math.rad(PEDAL_ANGLE*U)*E end end end)local u=Z.PBrake.Changed:Connect(function()local U=Z.PBrake.Value if K then Q:FireServer("\080\066\114\097\107\101",U,HANDBRAKE,w,HANDBRAKE_ANG)else if HANDBRAKE and w~=nil then if U then w.W.Motor.DesiredAngle=math.rad(HANDBRAKE_ANG)else w.W.Motor.DesiredAngle=0 end end end end)game["\082\117\110 \083\101\114\118\105\099\101"].Stepped:connect(function()local Z=U.Wheels.FR.Base.CFrame:vectorToObjectSpace(U.Wheels.FR.Arm.CFrame.lookVector)local f=U.Wheels.FL.Base.CFrame:vectorToObjectSpace(U.Wheels.FL.Arm.CFrame.lookVector)local Q=(math.atan2(-Z.Z,Z.X)+math.atan2(-f.Z,f.X))/2 local K=-(Q-1.57)*STEER_MULT if STEERING_WHEEL and N~=nil then N.W.Motor.DesiredAngle=K end end)
--------------------------------------------------------------------------------

local Car = script.Parent.Car.Value
local Values = script.Parent.Values
local _Tune = require(Car["A-Chassis Tune"])
local Handler = Car:WaitForChild("INTERIOR_PACK")
local FE = workspace.FilteringEnabled

local INT_PCK = nil
for _, Child in pairs(Car.Misc:GetDescendants()) do
	if Child:IsA("ObjectValue") and Child.Name == "INTERIOR_PACK" then
		INT_PCK = Child.Value
	end
end
if INT_PCK == nil then
	script:Destroy()
end

local HB = INT_PCK:FindFirstChild("Handbrake")
local PS = INT_PCK:FindFirstChild("Paddle_Shifter")
local PD = INT_PCK:FindFirstChild("Pedals")
local SH = INT_PCK:FindFirstChild("Shifter")
local SW = INT_PCK:FindFirstChild("Steering_Wheel")

local Val = 0
local SEQ = 1
if SEQ_INVERTED then
	SEQ = -1
end
local PED = 1
if PED_INVERTED then
	PED = -1
end

local Gear = Values.Gear.Changed:Connect(function()
	local Gear = Values.Gear.Value
	local Shift = "Down"
	if Gear > Val then
		Shift = "Up"
	end
	Val = Gear

	if FE then
		Handler:FireServer(
			"Gear",
			Gear,
			Shift,
			PADDLE_SHIFTER,
			PEDALS,
			SHIFTER,
			PS,
			PD,
			SH,
			PADDLE_ANG,
			PADDLE_INVERTED,
			SHIFTER_TYPE,
			SEQ,
			SHIFT_TIME,
			VERTICAL_ANG,
			HORIZONTAL_ANG
		)
	else
		if PEDALS and PD ~= nil then
			PD.C.Motor.DesiredAngle = math.rad(PEDAL_ANGLE) * PED
		end

		if PADDLE_SHIFTER and PS ~= nil then
			if Shift == "Up" then
				if PADDLE_INVERTED then
					PS.L.Motor.DesiredAngle = math.rad(PADDLE_ANG)
				else
					PS.R.Motor.DesiredAngle = math.rad(PADDLE_ANG)
				end
			else
				if PADDLE_INVERTED then
					PS.R.Motor.DesiredAngle = math.rad(PADDLE_ANG)
				else
					PS.L.Motor.DesiredAngle = math.rad(PADDLE_ANG)
				end
			end
			wait(SHIFT_TIME / 2)
			PS.R.Motor.DesiredAngle = 0
			PS.L.Motor.DesiredAngle = 0
		end

		if SHIFTER and SH ~= nil then
			local MOT1 = SH.W1.Motor
			local MOT2 = SH.W2.Motor
			MOT2.DesiredAngle = 0
			wait(SHIFT_TIME / 2)
			if SHIFTER_TYPE == "Seq" then
				if Shift == "Up" then
					MOT2.DesiredAngle = math.rad(VERTICAL_ANG) * SEQ
					wait(SHIFT_TIME / 2)
					MOT2.DesiredAngle = 0
				else
					MOT2.DesiredAngle = -math.rad(VERTICAL_ANG) * SEQ
					wait(SHIFT_TIME / 2)
					MOT2.DesiredAngle = 0
				end
			else
				if Gear == -1 then
					MOT1.DesiredAngle = math.floor((#_Tune["Ratios"] - 1) / 4) * 2 * math.rad(HORIZONTAL_ANG)
					wait(SHIFT_TIME / 2)

					if #_Tune["Ratios"] % 2 == 0 then
						MOT2.DesiredAngle = math.rad(VERTICAL_ANG)
					else
						MOT2.DesiredAngle = -math.rad(VERTICAL_ANG)
					end
				elseif Gear == 0 then
					MOT1.DesiredAngle = 0
				elseif Gear > 0 then
					if Shift == "Up" then
						if Val == 0 then
							MOT1.DesiredAngle = -math.floor((#_Tune["Ratios"] - 1) / 4) * math.rad(HORIZONTAL_ANG)
							wait(SHIFT_TIME / 2)
							MOT2.DesiredAngle = math.rad(VERTICAL_ANG)
						elseif Gear % 2 == 0 then
							MOT2.DesiredAngle = -math.rad(VERTICAL_ANG)
						else
							MOT1.DesiredAngle = MOT1.DesiredAngle + math.rad(HORIZONTAL_ANG)
							wait(SHIFT_TIME / 2)
							MOT2.DesiredAngle = math.rad(VERTICAL_ANG)
						end
					else
						if Gear % 2 == 0 then
							MOT1.DesiredAngle = MOT1.DesiredAngle - math.rad(HORIZONTAL_ANG)
							wait(SHIFT_TIME / 2)
							MOT2.DesiredAngle = -math.rad(VERTICAL_ANG)
						else
							MOT2.DesiredAngle = math.rad(VERTICAL_ANG)
						end
					end
				end
			end
		end

		if PEDALS and PD ~= nil then
			PD.C.Motor.DesiredAngle = 0
		end
	end
end)

local Throttle = Values.Throttle.Changed:Connect(function()
	local Throttle = Values.Throttle.Value
	if FE then
		Handler:FireServer("Throttle", Throttle, PEDALS, PD, PEDAL_ANGLE, PED)
	else
		if PEDALS and PD ~= nil then
			PD.T.Motor.DesiredAngle = math.rad(PEDAL_ANGLE * Throttle) * PED
		end
	end
end)

local Brake = Values.Brake.Changed:Connect(function()
	local Brake = Values.Brake.Value
	if FE then
		Handler:FireServer("Brake", Brake, PEDALS, PD, PEDAL_ANGLE, PED)
	else
		if PEDALS and PD ~= nil then
			PD.B.Motor.DesiredAngle = math.rad(PEDAL_ANGLE * Brake) * PED
		end
	end
end)

local PBrake = Values.PBrake.Changed:Connect(function()
	local PBrake = Values.PBrake.Value
	if FE then
		Handler:FireServer("PBrake", PBrake, HANDBRAKE, HB, HANDBRAKE_ANG)
	else
		if HANDBRAKE and HB ~= nil then
			if PBrake then
				HB.W.Motor.DesiredAngle = math.rad(HANDBRAKE_ANG)
			else
				HB.W.Motor.DesiredAngle = 0
			end
		end
	end
end)

game["Run Service"].Stepped:connect(function()
	local direction = Car.Wheels.FR.Base.CFrame:vectorToObjectSpace(Car.Wheels.FR.Arm.CFrame.lookVector)
	local direction2 = Car.Wheels.FL.Base.CFrame:vectorToObjectSpace(Car.Wheels.FL.Arm.CFrame.lookVector)
	local angle = ((math.atan2(-direction.Z, direction.X)) + (math.atan2(-direction2.Z, direction2.X))) / 2

	local Steer = -(angle - 1.57) * STEER_MULT

	if STEERING_WHEEL and SW ~= nil then
		SW.W.Motor.DesiredAngle = Steer
	end
end)
