--Automatic Gauge Scaling

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

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=false
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=false
	end
end





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

local UIS = game:GetService("UserInputService")
L = false
UIS.InputBegan:connect(function(i,GP) if not GP then if i.KeyCode == Enum.KeyCode.Z then
if L == false then
script.Parent.Left.ImageColor3 = Color3.fromRGB(142, 255, 169)
L = true
else
script.Parent.Left.ImageColor3 = Color3.fromRGB(255,255,255)
L = false
end
end end end)