if autoscaling then local k={}if _Tune.Config=="\070\087\068"or _Tune.Config=="\065\087\068"then if car.Wheels:FindFirstChild("\070\076")~=nil then table.insert(k,car.Wheels.FL)end if car.Wheels:FindFirstChild("\070\082")~=nil then table.insert(k,car.Wheels.FR)end if car.Wheels:FindFirstChild("\070")~=nil then table.insert(k,car.Wheels.F)end end if _Tune.Config=="\082\087\068"or _Tune.Config=="\065\087\068"then if car.Wheels:FindFirstChild("\082\076")~=nil then table.insert(k,car.Wheels.RL)end if car.Wheels:FindFirstChild("\082\082")~=nil then table.insert(k,car.Wheels.RR)end if car.Wheels:FindFirstChild("\082")~=nil then table.insert(k,car.Wheels.R)end end local a=0 for k,P in pairs(k)do if P.Size.x>a then a=P.Size.x end end k=nil for k,P in pairs(UNITS)do P.maxSpeed=math.ceil((((((P.scaling*a)*math.pi)*_lRPM)/60)/_Tune.Ratios[#_Tune.Ratios])/_Tune.FinalDrive)P.spInc=math.max(math.ceil(P.maxSpeed/200)*20,20)end end for k=0,revEnd*2,1 do local a=script.Parent.ln:clone()a.Parent=script.Parent.Tach a.Rotation=45+(k*225)/(revEnd*2)a.Num.Text=k/2 a.Num.Rotation=-a.Rotation if k*500>=math.floor(_pRPM/500)*500 then a.Frame.BackgroundColor3=Color3.new(1,0,0)if k<revEnd*2 then ln2=a:clone()ln2.Parent=script.Parent.Tach ln2.Rotation=45+((k+.5)*225)/(revEnd*2)ln2.Num:Destroy()ln2.Visible=true end end if k%2==0 then a.Frame.Size=UDim2.new(0,3,0,10)a.Frame.Position=UDim2.new(0,-1,0,100)a.Num.Visible=false else a.Num:Destroy()end a.Visible=true end local k=Instance.new("\070\114\097\109\101",script.Parent.Speedo)k.Name="\108\110\115"k.BackgroundTransparency=1 k.BorderSizePixel=0 k.Size=UDim2.new(0,0,0,0)for a=1,90,1 do local P=script.Parent.ln:clone()P.Parent=k P.Rotation=45+225*(a/90)if a%2==0 then P.Frame.Size=UDim2.new(0,2,0,10)P.Frame.Position=UDim2.new(0,-1,0,100)else P.Frame.Size=UDim2.new(0,3,0,5)end P.Num:Destroy()P.Visible=true end for k,a in pairs(UNITS)do local P=Instance.new("\070\114\097\109\101",script.Parent.Speedo)P.BackgroundTransparency=1 P.BorderSizePixel=0 P.Size=UDim2.new(0,0,0,0)P.Name=a.units if k~=1 then P.Visible=false end for k=0,a.maxSpeed,a.spInc do local z=script.Parent.ln:clone()z.Parent=P z.Rotation=45+225*(k/a.maxSpeed)z.Num.Text=k z.Num.TextSize=14 z.Num.Rotation=-z.Rotation z.Frame:Destroy()z.Num.Visible=true z.Visible=true end end if script.Parent.Parent.IsOn.Value then script.Parent:TweenPosition(UDim2.new(0,0,0,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad,1,true)end script.Parent.Parent.IsOn.Changed:connect(function()if script.Parent.Parent.IsOn.Value then script.Parent:TweenPosition(UDim2.new(0,0,0,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad,1,true)end end)script.Parent.Parent.Values.RPM.Changed:connect(function()script.Parent.Tach.Needle.Rotation=54+282*math.min(1,script.Parent.Parent.Values.RPM.Value/(revEnd*1000))end)script.Parent.Parent.Values.Gear.Changed:connect(function()local k=script.Parent.Parent.Values.Gear.Value if k==0 then k="\078"elseif k==-1 then k="\082"end script.Parent.Gear.Text=k end)script.Parent.Parent.Values.TCS.Changed:connect(function()if _Tune.TCSEnabled then if script.Parent.Parent.Values.TCS.Value then script.Parent.TCS.TextColor3=Color3.new(1,.66666666666667,0)script.Parent.TCS.TextStrokeColor3=Color3.new(1,.66666666666667,0)if script.Parent.Parent.Values.TCSActive.Value then wait()script.Parent.TCS.Visible=not script.Parent.TCS.Visible else wait()script.Parent.TCS.Visible=false end else script.Parent.TCS.Visible=true script.Parent.TCS.TextColor3=Color3.new(1,0,0)script.Parent.TCS.TextStrokeColor3=Color3.new(1,0,0)end else script.Parent.TCS.Visible=false end end)script.Parent.Parent.Values.TCSActive.Changed:connect(function()if _Tune.TCSEnabled then if script.Parent.Parent.Values.TCSActive.Value and script.Parent.Parent.Values.TCS.Value then wait()script.Parent.TCS.Visible=not script.Parent.TCS.Visible elseif not script.Parent.Parent.Values.TCS.Value then wait()script.Parent.TCS.Visible=true else wait()script.Parent.TCS.Visible=false end else script.Parent.TCS.Visible=false end end)script.Parent.TCS.Changed:connect(function()if _Tune.TCSEnabled then if script.Parent.Parent.Values.TCSActive.Value and script.Parent.Parent.Values.TCS.Value then wait()script.Parent.TCS.Visible=not script.Parent.TCS.Visible elseif not script.Parent.Parent.Values.TCS.Value then wait()script.Parent.TCS.Visible=true end else if script.Parent.TCS.Visible then script.Parent.TCS.Visible=false end end end)script.Parent.Parent.Values.ABS.Changed:connect(function()if _Tune.ABSEnabled then if script.Parent.Parent.Values.ABS.Value then script.Parent.ABS.TextColor3=Color3.new(1,.66666666666667,0)script.Parent.ABS.TextStrokeColor3=Color3.new(1,.66666666666667,0)if script.Parent.Parent.Values.ABSActive.Value then wait()script.Parent.ABS.Visible=not script.Parent.ABS.Visible else wait()script.Parent.ABS.Visible=false end else script.Parent.ABS.Visible=true script.Parent.ABS.TextColor3=Color3.new(1,0,0)script.Parent.ABS.TextStrokeColor3=Color3.new(1,0,0)end else script.Parent.ABS.Visible=false end end)script.Parent.Parent.Values.ABSActive.Changed:connect(function()if _Tune.ABSEnabled then if script.Parent.Parent.Values.ABSActive.Value and script.Parent.Parent.Values.ABS.Value then wait()script.Parent.ABS.Visible=not script.Parent.ABS.Visible elseif not script.Parent.Parent.Values.ABS.Value then wait()script.Parent.ABS.Visible=true else wait()script.Parent.ABS.Visible=false end else script.Parent.ABS.Visible=false end end)script.Parent.ABS.Changed:connect(function()if _Tune.ABSEnabled then if script.Parent.Parent.Values.ABSActive.Value and script.Parent.Parent.Values.ABS.Value then wait()script.Parent.ABS.Visible=not script.Parent.ABS.Visible elseif not script.Parent.Parent.Values.ABS.Value then wait()script.Parent.ABS.Visible=true end else if script.Parent.ABS.Visible then script.Parent.ABS.Visible=false end end end)function PBrake()script.Parent.PBrake.Visible=script.Parent.Parent.Values.PBrake.Value end script.Parent.Parent.Values.PBrake.Changed:connect(PBrake)function Gear()if script.Parent.Parent.Values.TransmissionMode.Value=="\065\117\116\111"then script.Parent.TMode.Text="\065\047\084"script.Parent.TMode.BackgroundColor3=Color3.new(1,.66666666666667,0)elseif script.Parent.Parent.Values.TransmissionMode.Value=="\083\101\109\105"then script.Parent.TMode.Text="\083\047\084"script.Parent.TMode.BackgroundColor3=Color3.new(0,.66666666666667,.49803921568627)else script.Parent.TMode.Text="\077\047\084"script.Parent.TMode.BackgroundColor3=Color3.new(1,.33333333333333,.5)end end script.Parent.Parent.Values.TransmissionMode.Changed:connect(Gear)script.Parent.Parent.Values.Velocity.Changed:connect(function(k)script.Parent.Speedo.Needle.Rotation=45+225*math.min(1,(UNITS[currentUnits].scaling*script.Parent.Parent.Values.Velocity.Value.Magnitude)/UNITS[currentUnits].maxSpeed)script.Parent.Speed.Text=math.floor(UNITS[currentUnits].scaling*script.Parent.Parent.Values.Velocity.Value.Magnitude)..(" "..UNITS[currentUnits].units)end)script.Parent.Speed.MouseButton1Click:connect(function()if currentUnits==#UNITS then currentUnits=1 else currentUnits=currentUnits+1 end for k,a in pairs(script.Parent.Speedo:GetChildren())do a.Visible=a.Name==UNITS[currentUnits].units or a.Name=="\078\101\101\100\108\101"or a.Name=="\108\110\115"end script.Parent.Speed.Text=math.floor(UNITS[currentUnits].scaling*script.Parent.Parent.Values.Velocity.Value.Magnitude)..(" "..UNITS[currentUnits].units)end)wait(.1)Gear()PBrake()

if autoscaling then
	local Drive={}
	if _Tune.Config == "FWD" or _Tune.Config == "AWD" then
		if car.Wheels:FindFirstChild("FL")~= nil then
			table.insert(Drive,car.Wheels.FL)
		end
		if car.Wheels:FindFirstChild("FR")~= nil then
			table.insert(Drive,car.Wheels.FR)
		end
		if car.Wheels:FindFirstChild("F")~= nil then
			table.insert(Drive,car.Wheels.F)
		end
	end
	if _Tune.Config == "RWD" or _Tune.Config == "AWD" then
		if car.Wheels:FindFirstChild("RL")~= nil then
			table.insert(Drive,car.Wheels.RL)
		end
		if car.Wheels:FindFirstChild("RR")~= nil then
			table.insert(Drive,car.Wheels.RR)
		end
		if car.Wheels:FindFirstChild("R")~= nil then
			table.insert(Drive,car.Wheels.R)
		end
	end

	local wDia = 0
	for i,v in pairs(Drive) do
		if v.Size.x>wDia then wDia = v.Size.x end
	end
	Drive = nil
	for i,v in pairs(UNITS) do
		v.maxSpeed = math.ceil(v.scaling*wDia*math.pi*_lRPM/60/_Tune.Ratios[#_Tune.Ratios]/_Tune.FinalDrive)
		v.spInc = math.max(math.ceil(v.maxSpeed/200)*20,20)
	end
end

for i=0,revEnd*2 do
	local ln = script.Parent.ln:clone()
	ln.Parent = script.Parent.Tach
	ln.Rotation = 45 + i * 225 / (revEnd*2)
	ln.Num.Text = i/2
	ln.Num.Rotation = -ln.Rotation
	if i*500>=math.floor(_pRPM/500)*500 then
		ln.Frame.BackgroundColor3 = Color3.new(1,0,0)
		if i<revEnd*2 then
			ln2 = ln:clone()
			ln2.Parent = script.Parent.Tach
			ln2.Rotation = 45 + (i+.5) * 225 / (revEnd*2)
			ln2.Num:Destroy()
			ln2.Visible=true
		end
	end
	if i%2==0 then
		ln.Frame.Size = UDim2.new(0,3,0,10)
		ln.Frame.Position = UDim2.new(0,-1,0,100)
		ln.Num.Visible = false
	else
		ln.Num:Destroy()
	end
	ln.Visible=true
end

local lns = Instance.new("Frame",script.Parent.Speedo)
lns.Name = "lns"
lns.BackgroundTransparency = 1
lns.BorderSizePixel = 0
lns.Size = UDim2.new(0,0,0,0)
for i=1,90 do
	local ln = script.Parent.ln:clone()
	ln.Parent = lns
	ln.Rotation = 45 + 225*(i/90)
	if i%2==0 then
		ln.Frame.Size = UDim2.new(0,2,0,10)
		ln.Frame.Position = UDim2.new(0,-1,0,100)
	else
		ln.Frame.Size = UDim2.new(0,3,0,5)
	end
	ln.Num:Destroy()
	ln.Visible=true
end

for i,v in pairs(UNITS) do
	local lnn = Instance.new("Frame",script.Parent.Speedo)
	lnn.BackgroundTransparency = 1
	lnn.BorderSizePixel = 0
	lnn.Size = UDim2.new(0,0,0,0)
	lnn.Name = v.units
	if i~= 1 then lnn.Visible=false end
	
	for i=0,v.maxSpeed,v.spInc do
		local ln = script.Parent.ln:clone()
		ln.Parent = lnn
		ln.Rotation = 45 + 225*(i/v.maxSpeed)
		ln.Num.Text = i
		ln.Num.TextSize = 14
		ln.Num.Rotation = -ln.Rotation
		ln.Frame:Destroy()
		ln.Num.Visible=true
		ln.Visible=true
	end
end

if 	script.Parent.Parent.IsOn.Value then
	script.Parent:TweenPosition(UDim2.new(0, 0, 0, 0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad,1,true)
end

script.Parent.Parent.IsOn.Changed:connect(function()
	if script.Parent.Parent.IsOn.Value then
		script.Parent:TweenPosition(UDim2.new(0, 0, 0, 0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad,1,true)
	end
end)

script.Parent.Parent.Values.RPM.Changed:connect(function()
	script.Parent.Tach.Needle.Rotation = 54 + 282 * math.min(1,script.Parent.Parent.Values.RPM.Value / (revEnd*1000))
end)

script.Parent.Parent.Values.Gear.Changed:connect(function()
	local gearText = script.Parent.Parent.Values.Gear.Value
	if gearText == 0 then gearText = "N"
	elseif gearText == -1 then gearText = "R"
	end
	script.Parent.Gear.Text = gearText
end)

script.Parent.Parent.Values.TCS.Changed:connect(function()
	if _Tune.TCSEnabled then
		if script.Parent.Parent.Values.TCS.Value then
			script.Parent.TCS.TextColor3 = Color3.new(1,170/255,0)
			script.Parent.TCS.TextStrokeColor3 = Color3.new(1,170/255,0)
			if script.Parent.Parent.Values.TCSActive.Value then
				wait()
				script.Parent.TCS.Visible = not script.Parent.TCS.Visible
			else
				wait()
				script.Parent.TCS.Visible = false
			end
		else
			script.Parent.TCS.Visible = true
			script.Parent.TCS.TextColor3 = Color3.new(1,0,0)
			script.Parent.TCS.TextStrokeColor3 = Color3.new(1,0,0)
		end
	else
		script.Parent.TCS.Visible = false
	end
end)

script.Parent.Parent.Values.TCSActive.Changed:connect(function()
	if _Tune.TCSEnabled then
		if script.Parent.Parent.Values.TCSActive.Value and script.Parent.Parent.Values.TCS.Value then
			wait()
			script.Parent.TCS.Visible = not script.Parent.TCS.Visible
		elseif not script.Parent.Parent.Values.TCS.Value then
			wait()
			script.Parent.TCS.Visible = true
		else
			wait()
			script.Parent.TCS.Visible = false
		end
	else
		script.Parent.TCS.Visible = false
	end
end)

script.Parent.TCS.Changed:connect(function()
	if _Tune.TCSEnabled then
		if script.Parent.Parent.Values.TCSActive.Value and script.Parent.Parent.Values.TCS.Value then
			wait()
			script.Parent.TCS.Visible = not script.Parent.TCS.Visible
		elseif not script.Parent.Parent.Values.TCS.Value then
			wait()
			script.Parent.TCS.Visible = true
		end
	else
		if script.Parent.TCS.Visible then
			script.Parent.TCS.Visible = false
		end
	end
end)

script.Parent.Parent.Values.ABS.Changed:connect(function()
	if _Tune.ABSEnabled then
		if script.Parent.Parent.Values.ABS.Value then
			script.Parent.ABS.TextColor3 = Color3.new(1,170/255,0)
			script.Parent.ABS.TextStrokeColor3 = Color3.new(1,170/255,0)
			if script.Parent.Parent.Values.ABSActive.Value then
				wait()
				script.Parent.ABS.Visible = not script.Parent.ABS.Visible
			else
				wait()
				script.Parent.ABS.Visible = false
			end
		else
			script.Parent.ABS.Visible = true
			script.Parent.ABS.TextColor3 = Color3.new(1,0,0)
			script.Parent.ABS.TextStrokeColor3 = Color3.new(1,0,0)
		end
	else
		script.Parent.ABS.Visible = false
	end
end)

script.Parent.Parent.Values.ABSActive.Changed:connect(function()
	if _Tune.ABSEnabled then
		if script.Parent.Parent.Values.ABSActive.Value and script.Parent.Parent.Values.ABS.Value then
			wait()
			script.Parent.ABS.Visible = not script.Parent.ABS.Visible
		elseif not script.Parent.Parent.Values.ABS.Value then
			wait()
			script.Parent.ABS.Visible = true
		else
			wait()
			script.Parent.ABS.Visible = false
		end
	else
		script.Parent.ABS.Visible = false
	end
end)

script.Parent.ABS.Changed:connect(function()
	if _Tune.ABSEnabled then
		if script.Parent.Parent.Values.ABSActive.Value and script.Parent.Parent.Values.ABS.Value then
			wait()
			script.Parent.ABS.Visible = not script.Parent.ABS.Visible
		elseif not script.Parent.Parent.Values.ABS.Value then
			wait()
			script.Parent.ABS.Visible = true
		end
	else
		if script.Parent.ABS.Visible then
			script.Parent.ABS.Visible = false
		end
	end
end)


function PBrake()
	script.Parent.PBrake.Visible = script.Parent.Parent.Values.PBrake.Value
end
script.Parent.Parent.Values.PBrake.Changed:connect(PBrake)

function Gear()
	if script.Parent.Parent.Values.TransmissionMode.Value == "Auto" then
		script.Parent.TMode.Text = "A/T"
		script.Parent.TMode.BackgroundColor3 = Color3.new(1,170/255,0)
	elseif script.Parent.Parent.Values.TransmissionMode.Value == "Semi" then
		script.Parent.TMode.Text = "S/T"
		script.Parent.TMode.BackgroundColor3 = Color3.new(0, 170/255, 127/255) 
	else
		script.Parent.TMode.Text = "M/T"
		script.Parent.TMode.BackgroundColor3 = Color3.new(1,85/255,.5)
	end
end
script.Parent.Parent.Values.TransmissionMode.Changed:connect(Gear)

script.Parent.Parent.Values.Velocity.Changed:connect(function(property)
	script.Parent.Speedo.Needle.Rotation =45 + 225 * math.min(1,UNITS[currentUnits].scaling*script.Parent.Parent.Values.Velocity.Value.Magnitude/UNITS[currentUnits].maxSpeed)
	script.Parent.Speed.Text = math.floor(UNITS[currentUnits].scaling*script.Parent.Parent.Values.Velocity.Value.Magnitude) .. " "..UNITS[currentUnits].units
end)

script.Parent.Speed.MouseButton1Click:connect(function()
	if currentUnits==#UNITS then
		currentUnits = 1
	else
		currentUnits = currentUnits+1
	end
	for i,v in pairs(script.Parent.Speedo:GetChildren()) do
		v.Visible=v.Name==UNITS[currentUnits].units or v.Name=="Needle" or v.Name=="lns"
	end
	script.Parent.Speed.Text = math.floor(UNITS[currentUnits].scaling*script.Parent.Parent.Values.Velocity.Value.Magnitude) .. " "..UNITS[currentUnits].units
end)

wait(.1)
Gear()
PBrake()
