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

if STEER_VERS == "New" then
	if FE then
		Handler:FireServer("Loop",STEERING_WHEEL,SW,STEER_MULT)
	else
		spawn(function()
			while wait() do
				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
					print("A")
					SW.W.Motor.CurrentAngle = Steer
				end
			end
		end)
	end
else
	local Steering = Values.SteerC.Changed:Connect(function()
		local Steer = Values.SteerC.Value
		if FE then
			Handler:FireServer("Steering",Steer,STEERING_WHEEL,SW,STEER_MULT)
		else

			if STEERING_WHEEL and SW ~= nil then
				SW.W.Motor.DesiredAngle = math.rad(Steer*STEER_MULT*70)
			end
		end
	end)
end
