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