local I="\077\080\072"local T=script.Parent.Parent.Car.Value local N=require(T["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local l=script.Parent.Parent.Values local x=.9144 local w=.56818181818182 local t=0 local o=N.Boost local c=0 local J=.9 local E=.8 if N.Redline>=7000 then c=8000 script.Parent.RPM.ImageLabel.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\050\053\057\048\050\050\048\057"end if N.Redline>=8000 then c=9000 script.Parent.RPM.ImageLabel.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\052\052\051\050\051\050\048\056"end if N.Redline>=9000 then c=10000 script.Parent.RPM.ImageLabel.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\052\052\051\050\051\056\051\048"end if N.Redline>=10000 then c=13000 script.Parent.RPM.ImageLabel.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\052\052\051\050\052\053\056\056"end script.Parent:WaitForChild("\075\112\104\077\112\104")if I=="\075\080\072"then t=x script.Parent.KphMph.Text="\075\080\072"end if I=="\077\080\072"then t=w script.Parent.KphMph.Text="\077\080\072"end game["\082\117\110 \083\101\114\118\105\099\101"].Stepped:connect(function()script.Parent.Speed.Text=math.floor(l.Velocity.Value.Magnitude*t)script.Parent.RPM.Needle.Rotation=script.Parent.RPM.Needle.Rotation*J+(-120+(l.RPM.Value/c)*240)*(1-J)if l.Gear.Value==-1 then script.Parent.Gear.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\052\052\051\049\056\049\057\050"end if l.Gear.Value==0 then script.Parent.Gear.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\052\052\051\049\056\052\057\051"end if l.Gear.Value==1 then script.Parent.Gear.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\050\053\057\048\048\050\051\057"end if l.Gear.Value==2 then script.Parent.Gear.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\050\053\057\048\048\053\055\051"end if l.Gear.Value==3 then script.Parent.Gear.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\050\053\057\048\048\057\050\049"end if l.Gear.Value==4 then script.Parent.Gear.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\050\053\057\048\049\049\057\055"end if l.Gear.Value==5 then script.Parent.Gear.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\050\053\057\048\049\052\049\056"end if l.Gear.Value==6 then script.Parent.Gear.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\050\053\057\048\049\054\054\055"end local I=T.Wheels.FR.Base.CFrame:vectorToObjectSpace(T.Wheels.FR.Arm.CFrame.lookVector)local x=T.Wheels.FL.Base.CFrame:vectorToObjectSpace(T.Wheels.FL.Arm.CFrame.lookVector)local w=(math.atan2(-I.Z,I.X)+math.atan2(-x.Z,x.X))/2 local y=(w-1.57)*6 local X=Ray.new(T.Wheels.RL.Position,(T.Wheels.RL.Arm.CFrame*CFrame.Angles(-math.pi/2,0,0)).lookVector*(.05+T.Wheels.RL.Size.x/2))local s=0 if workspace:FindPartOnRay(X,T)~=nil then s=1 end local V=Ray.new(T.Wheels.RL.Position,(T.Wheels.RR.Arm.CFrame*CFrame.Angles(-math.pi/2,0,0)).lookVector*(.05+T.Wheels.RR.Size.x/2))local v=0 if workspace:FindPartOnRay(V,T)~=nil then v=1 end local u=math.min(math.max(math.abs((T.Wheels.RL.RotVelocity.Magnitude*T.Wheels.RL.Size.x)/2-T.Wheels.RL.Velocity.Magnitude)-30,0),50)*s local Q=math.min(math.max(math.abs((T.Wheels.RR.RotVelocity.Magnitude*T.Wheels.RR.Size.x)/2-T.Wheels.RR.Velocity.Magnitude)-30,0),50)*v if u>=1e-06 and(Q>=1e-06 and(y>1 and l.Velocity.Value.Magnitude>15))or u>=1e-06 and(Q>=1e-06 and(y<-1 and l.Velocity.Value.Magnitude>15))then script.Parent.Drift.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\050\053\057\048\048\048\048\050"else script.Parent.Drift.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\055\050\053\056\057\057\055\053\050"end if N.TCSEnabled==true then script.Parent.TCS.Visible=true if script.Parent.Parent.Values.TCS.Value==true then script.Parent.TCS.TextColor3=Color3.new(1,1,1)else if script.Parent.Parent.Values.TCSActive.Value==true then script.Parent.TCS.TextColor3=Color3.new(1,1,0)else script.Parent.TCS.TextColor3=Color3.new(1,0,0)end end else script.Parent.TCS.Visible=false end if N.ABSEnabled==true then script.Parent.ABS.Visible=true if script.Parent.Parent.Values.ABS.Value==true then script.Parent.ABS.TextColor3=Color3.new(1,1,1)else if script.Parent.Parent.Values.ABSActive.Value==true then script.Parent.ABS.TextColor3=Color3.new(1,1,0)else script.Parent.ABS.TextColor3=Color3.new(1,0,0)end end else script.Parent.ABS.Visible=false end script.Parent.Boost.Needle.Rotation=script.Parent.Boost.Needle.Rotation*J+((-110+(l.Boost.Value/15)*90)+(l.Boost.Value/o)*20)*(1-J)if N.Aspiration=="\078\097\116\117\114\097\108"then script.Parent.Boost.Visible=false else script.Parent.Boost.Visible=true end script.Parent.Throttle.Rotation=script.Parent.Throttle.Rotation*E+(script.Parent.Parent.Values.Throttle.Value*130)*(1-E)script.Parent.Brake.Rotation=script.Parent.Brake.Rotation*E+(script.Parent.Parent.Values.Brake.Value*130)*(1-E)end)
--TUNE
local SpeedType = "MPH" -- MPH or KPH

local car = script.Parent.Parent.Car.Value
local _Tune = require(car["A-Chassis Tune"])
local Values = script.Parent.Parent.Values
local KPH = (10 / 12) * 1.09728
local MPH = (10 / 12) * (60 / 88)
local speed = 0
local Boost = _Tune.Boost
local Red = 0
local smooth = 0.9
local TBsmooth = 0.8

if _Tune.Redline >= 7000 then
	Red = 8000
	script.Parent.RPM.ImageLabel.Image = "rbxassetid://1725902209"
end
if _Tune.Redline >= 8000 then
	Red = 9000
	script.Parent.RPM.ImageLabel.Image = "rbxassetid://1744323208"
end
if _Tune.Redline >= 9000 then
	Red = 10000
	script.Parent.RPM.ImageLabel.Image = "rbxassetid://1744323830"
end
if _Tune.Redline >= 10000 then
	Red = 13000
	script.Parent.RPM.ImageLabel.Image = "rbxassetid://1744324588"
end

script.Parent:WaitForChild("KphMph")

if SpeedType == "KPH" then
	speed = KPH
	script.Parent.KphMph.Text = "KPH"
end
if SpeedType == "MPH" then
	speed = MPH
	script.Parent.KphMph.Text = "MPH"
end

game["Run Service"].Stepped:connect(function()
	script.Parent.Speed.Text = math.floor(Values.Velocity.Value.Magnitude * speed)
	script.Parent.RPM.Needle.Rotation = script.Parent.RPM.Needle.Rotation * smooth
		+ (-120 + ((Values.RPM.Value / Red) * 240)) * (1 - smooth)

	if Values.Gear.Value == -1 then
		script.Parent.Gear.Image = "rbxassetid://1744318192"
	end
	if Values.Gear.Value == 0 then
		script.Parent.Gear.Image = "rbxassetid://1744318493"
	end
	if Values.Gear.Value == 1 then
		script.Parent.Gear.Image = "rbxassetid://1725900239"
	end
	if Values.Gear.Value == 2 then
		script.Parent.Gear.Image = "rbxassetid://1725900573"
	end
	if Values.Gear.Value == 3 then
		script.Parent.Gear.Image = "rbxassetid://1725900921"
	end
	if Values.Gear.Value == 4 then
		script.Parent.Gear.Image = "rbxassetid://1725901197"
	end
	if Values.Gear.Value == 5 then
		script.Parent.Gear.Image = "rbxassetid://1725901418"
	end
	if Values.Gear.Value == 6 then
		script.Parent.Gear.Image = "rbxassetid://1725901667"
	end

	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 anglez = (angle - 1.57) * 6

	local r1 = Ray.new(
		car.Wheels.RL.Position,
		(car.Wheels.RL.Arm.CFrame * CFrame.Angles(-math.pi / 2, 0, 0)).lookVector * (0.05 + car.Wheels.RL.Size.x / 2)
	)
	local r1hit = 0
	if workspace:FindPartOnRay(r1, car) ~= nil then
		r1hit = 1
	end

	local r2 = Ray.new(
		car.Wheels.RL.Position,
		(car.Wheels.RR.Arm.CFrame * CFrame.Angles(-math.pi / 2, 0, 0)).lookVector * (0.05 + car.Wheels.RR.Size.x / 2)
	)
	local r2hit = 0
	if workspace:FindPartOnRay(r2, car) ~= nil then
		r2hit = 1
	end

	local rl = math.min(
		(
			math.max(
				math.abs(
					(car.Wheels.RL.RotVelocity.Magnitude * car.Wheels.RL.Size.x / 2) - car.Wheels.RL.Velocity.Magnitude
				) - 30,
				0
			)
		),
		50
	) * r1hit
	local rr = math.min(
		(
			math.max(
				math.abs(
					(car.Wheels.RR.RotVelocity.Magnitude * car.Wheels.RR.Size.x / 2) - car.Wheels.RR.Velocity.Magnitude
				) - 30,
				0
			)
		),
		50
	) * r2hit

	if
		rl >= 0.000001 and rr >= 0.000001 and anglez > 1 and Values.Velocity.Value.Magnitude > 15
		or rl >= 0.000001 and rr >= 0.000001 and anglez < -1 and Values.Velocity.Value.Magnitude > 15
	then
		script.Parent.Drift.Image = "rbxassetid://1725900002"
	else
		script.Parent.Drift.Image = "rbxassetid://1725899752"
	end

	--TCS and ABS
	if _Tune.TCSEnabled == true then
		script.Parent.TCS.Visible = true
		if script.Parent.Parent.Values.TCS.Value == true then
			script.Parent.TCS.TextColor3 = Color3.new(1, 1, 1)
		else
			if script.Parent.Parent.Values.TCSActive.Value == true then
				script.Parent.TCS.TextColor3 = Color3.new(1, 1, 0)
			else
				script.Parent.TCS.TextColor3 = Color3.new(1, 0, 0)
			end
		end
	else
		script.Parent.TCS.Visible = false
	end

	if _Tune.ABSEnabled == true then
		script.Parent.ABS.Visible = true
		if script.Parent.Parent.Values.ABS.Value == true then
			script.Parent.ABS.TextColor3 = Color3.new(1, 1, 1)
		else
			if script.Parent.Parent.Values.ABSActive.Value == true then
				script.Parent.ABS.TextColor3 = Color3.new(1, 1, 0)
			else
				script.Parent.ABS.TextColor3 = Color3.new(1, 0, 0)
			end
		end
	else
		script.Parent.ABS.Visible = false
	end

	--boost
	script.Parent.Boost.Needle.Rotation = script.Parent.Boost.Needle.Rotation * smooth
		+ (-110 + ((Values.Boost.Value / 15) * 90) + ((Values.Boost.Value / Boost) * 20)) * (1 - smooth)
	if _Tune.Aspiration == "Natural" then
		script.Parent.Boost.Visible = false
	else
		script.Parent.Boost.Visible = true
	end

	-- Throttle and Brake
	script.Parent.Throttle.Rotation = script.Parent.Throttle.Rotation * TBsmooth
		+ (script.Parent.Parent.Values.Throttle.Value * 130) * (1 - TBsmooth)
	script.Parent.Brake.Rotation = script.Parent.Brake.Rotation * TBsmooth
		+ (script.Parent.Parent.Values.Brake.Value * 130) * (1 - TBsmooth)
end)
