-----------------------------------------------------------------------------------------------



script.Parent:WaitForChild("Gear")
script.Parent:WaitForChild("Speed")
script.Parent:WaitForChild("Needle")

local player=game.Players.LocalPlayer
local mouse=player:GetMouse()

local car = script.Parent.Parent.Car.Value
car.DriveSeat.HeadsUpDisplay = false

local _Tune = require(car["A-Chassis Tune"])

local _pRPM = _Tune.PeakRPM
local _lRPM = _Tune.Redline

local currentUnits = 1
local revEnd = math.ceil(_lRPM/1000)

script.Parent.Parent.Values.Gear.Changed:connect(function()
	local gearText = script.Parent.Parent.Values.Gear.Value
	if gearText == 0 then 
		gearText = "<i> <b>" .. "N" .. "</b> </i>"

	elseif gearText == -1 then gearText = "<i> <b>" .. "R" .. "</b> </i>"
	end
	script.Parent.Gear.Text = "<i> <b>" .. gearText .. "</b> </i>"
	script.Parent.Gear.Font = Enum.Font.Oswald
end)

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

script.Parent.Parent.Values.Velocity.Changed:connect(function(property)
	script.Parent.Speed.Text = "<i>" .. math.floor(UNITS[currentUnits].scaling*script.Parent.Parent.Values.Velocity.Value.Magnitude) .. "</i>"
end)

wait(.1)

local RPMOFF = RedlineRPM - 100

script.Parent.Parent.Values.RPM.Changed:connect(function()
	local Roundspeed = script.Parent.Parent.Values.RPM.Value

	if Roundspeed <= RedlineRPM then 
		script.Parent.Gear.TextColor3 = Color3.fromRGB(24, 255, 145)
		script.Parent.Center.ImageColor3 = Color3.fromRGB(24, 255, 145)


	elseif Roundspeed >= RPMOFF then 
		script.Parent.Gear.TextColor3 = Color3.fromRGB(234, 31, 84)
		script.Parent.Center.ImageColor3 = Color3.fromRGB(234, 31, 84)

	end 

end)

local values = script.Parent.Parent.Values
local gauges = script.Parent

values.TCS.Changed:connect(function()
	if _Tune.TCSEnabled then
		if values.TCS.Value then
			gauges.TCS.ImageColor3 = Color3.fromRGB(234, 31, 84)

			if values.TCSActive.Value then
				wait()
				--gauges.TCS.Visible = not gauges.TCS.Visible
			else
				wait()
				gauges.TCS.ImageColor3 = Color3.fromRGB(78, 78, 78)
			end
		else
			gauges.TCS.Visible = true
			gauges.TCS.ImageColor3 = Color3.fromRGB(234, 31, 84)

		end
	else
		gauges.TCS.ImageColor3 = Color3.fromRGB(78, 78, 78)
	end
end)

values.TCSActive.Changed:connect(function()
	if _Tune.TCSEnabled then
		if values.TCSActive.Value and values.TCS.Value then
			wait()
			
		elseif not values.TCS.Value then
			wait()
			gauges.TCS.Visible = true
		else
			wait()
			gauges.TCS.ImageColor3 = Color3.fromRGB(78, 78, 78)
		end
	else
		gauges.TCS.ImageColor3 = Color3.fromRGB(78, 78, 78)
	end
end)

gauges.TCS.Changed:connect(function()
	if _Tune.TCSEnabled then
		if values.TCSActive.Value and values.TCS.Value then
			wait()
			
		elseif not values.TCS.Value then
			wait()
			gauges.TCS.Visible = true
		end
	else
		if gauges.TCS.Visible then
			gauges.TCS.ImageColor3 = Color3.fromRGB(78, 78, 78)
		end
	end
end)

values.ABS.Changed:connect(function()
	if _Tune.ABSEnabled then
		if values.ABS.Value then
			gauges.ABS.ImageColor3 = Color3.fromRGB(234, 31, 84)

			if values.ABSActive.Value then
				wait()
				gauges.ABS.Visible = not gauges.ABS.Visible
			else
				wait()
				gauges.ABS.ImageColor3 = Color3.fromRGB(78, 78, 78)
			end
		else
			gauges.ABS.Visible = true
			gauges.ABS.ImageColor3 = Color3.fromRGB(234, 31, 84)

		end
	else
		gauges.ABS.ImageColor3 = Color3.fromRGB(78, 78, 78)
	end
end)

values.ABSActive.Changed:connect(function()
	if _Tune.ABSEnabled then
		if values.ABSActive.Value and values.ABS.Value then
			wait()
			
		elseif not values.ABS.Value then
			wait()
			gauges.ABS.Visible = true
		else
			wait()
			gauges.ABS.ImageColor3 = Color3.fromRGB(78, 78, 78)
		end
	else
		gauges.ABS.ImageColor3 = Color3.fromRGB(78, 78, 78)
	end
end)

gauges.ABS.Changed:connect(function()
	if _Tune.ABSEnabled then
		if values.ABSActive.Value and values.ABS.Value then
			wait()
			
		elseif not values.ABS.Value then
			wait()
			gauges.ABS.Visible = true
		end
	else
		if gauges.ABS.Visible then
			gauges.ABS.ImageColor3 = Color3.fromRGB(78, 78, 78)
		end
	end
end)

gauges.PBrake.Visible = values.PBrake.Value

function PBrake()
	gauges.PBrake.Visible = values.PBrake.Value
end

values.PBrake.Changed:connect(PBrake)