local c="\077\080\072"local g=script.Parent.Parent.Car.Value local o=require(g["\065-\067\104\097\115\115\105\115 \084\117\110\101"])local p=script.Parent.Parent.Values local w=.9144 local R=.56818181818182 local J=0 local Y=o.Boost local y=0 local v=.9 local G=.8 if o.Redline>=7000 then y=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 o.Redline>=8000 then y=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 o.Redline>=9000 then y=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 o.Redline>=10000 then y=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 c=="\075\080\072"then J=w script.Parent.KphMph.Text="\075\080\072"end if c=="\077\080\072"then J=R 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(p.Velocity.Value.Magnitude*J)script.Parent.RPM.Needle.Rotation=script.Parent.RPM.Needle.Rotation*v+(-120+(p.RPM.Value/y)*240)*(1-v)if p.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 p.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 p.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 p.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 p.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 p.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 p.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 p.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 c=g.Wheels.FR.Base.CFrame:vectorToObjectSpace(g.Wheels.FR.Arm.CFrame.lookVector)local w=g.Wheels.FL.Base.CFrame:vectorToObjectSpace(g.Wheels.FL.Arm.CFrame.lookVector)local R=(math.atan2(-c.Z,c.X)+math.atan2(-w.Z,w.X))/2 local a=(R-1.57)*6 local B=Ray.new(g.Wheels.RL.Position,(g.Wheels.RL.Arm.CFrame*CFrame.Angles(-math.pi/2,0,0)).lookVector*(.05+g.Wheels.RL.Size.x/2))local u=0 if workspace:FindPartOnRay(B,g)~=nil then u=1 end local q=Ray.new(g.Wheels.RL.Position,(g.Wheels.RR.Arm.CFrame*CFrame.Angles(-math.pi/2,0,0)).lookVector*(.05+g.Wheels.RR.Size.x/2))local Q=0 if workspace:FindPartOnRay(q,g)~=nil then Q=1 end local T=math.min(math.max(math.abs((g.Wheels.RL.RotVelocity.Magnitude*g.Wheels.RL.Size.x)/2-g.Wheels.RL.Velocity.Magnitude)-30,0),50)*u local L=math.min(math.max(math.abs((g.Wheels.RR.RotVelocity.Magnitude*g.Wheels.RR.Size.x)/2-g.Wheels.RR.Velocity.Magnitude)-30,0),50)*Q if T>=1e-06 and(L>=1e-06 and(a>1 and p.Velocity.Value.Magnitude>15))or T>=1e-06 and(L>=1e-06 and(a<-1 and p.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 o.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 o.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*v+((-110+(p.Boost.Value/15)*90)+(p.Boost.Value/Y)*20)*(1-v)if o.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*G+(script.Parent.Parent.Values.Throttle.Value*130)*(1-G)script.Parent.Brake.Rotation=script.Parent.Brake.Rotation*G+(script.Parent.Parent.Values.Brake.Value*130)*(1-G)end)

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*(.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*(.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)
