-- Remade by Truenus(1)

wait(0.05)
local car = script.Parent.Parent.Car.Value
local GBrake = script.Parent.Parent.Values.Brake
local lighton=BrickColor.new("Institutional white")
local lightoff=BrickColor.new("Dark stone grey")
function LightOn()
	for i,v in pairs(car.Body.Lights:GetChildren()) do
		if v.Name=="Light" then
			v.BrickColor=lighton
			v.Material=Enum.Material.Neon
			v.Light.Enabled = true
			for i,v in pairs(car.Body.Lights:GetChildren()) do
		if v.Name=="R" then
			v.Material=Enum.Material.Neon
			v.Light.Enabled = true
			v.Transparency =.02
		end
	end
		end
	end
end

function LightOff()
	for i,v in pairs(car.Body.Lights:GetChildren()) do
		if v.Name=="Light" then
			v.BrickColor=lightoff
			v.Material=Enum.Material.SmoothPlastic
			v.Light.Enabled = false
			
			for i,v in pairs(car.Body.Lights:GetChildren()) do
			if v.Name=="R" then
				v.BrickColor=BrickColor.new("Maroon")
			v.Material=Enum.Material.SmoothPlastic
			v.Light.Enabled = false
			v.Transparency =0
			end
			end
			end
			end
	end
function Auto()
	if (game.Lighting:GetMinutesAfterMidnight()<390 or game.Lighting:GetMinutesAfterMidnight()>1050) then
		LightOn()
	else
		LightOff()
		end
end
script.Parent.MouseButton1Click:connect(function()
	if script.Parent.Text=="Lights: Auto" then
		LightOn()
		script.Parent.Text = "Lights: On"
	elseif script.Parent.Text == "Lights: On" then
		LightOff()
		script.Parent.Text = "Lights: Off"
	elseif script.Parent.Text == "Lights: Off" then
		Auto()
		script.Parent.Text = "Lights: Auto"
	end
end)
script.Parent.Parent.Values.Brake.Changed:connect(function()
	for i,v in pairs(car.Body.Lights:GetChildren()) do
		if v.Name=="R" then
			if v.Light.Enabled==true then
				if GBrake.Value>0 then
					v.Transparency=0
					v.Light.Brightness=12
					v.Light.Range=15
					v.BrickColor=BrickColor.new("Really red")
				else
					v.BrickColor=BrickColor.new("Maroon")
					v.Material=Enum.Material.Sand
					v.Transparency=.02
					v.Light.Brightness=8
					v.Light.Range=10
				end
			else
				v.Transparency=0
				if GBrake.Value>0 then
					v.Material=Enum.Material.Neon
					v.BrickColor=BrickColor.new("Really red")
				else
					v.BrickColor=BrickColor.new("Maroon")
					v.Material=Enum.Material.Sand
				end
			end
		elseif v.Name=="RR" then
			if GBrake.Value>0 then
				v.Material=Enum.Material.Neon
				if v.Light.Enabled then
					v.Transparency=1
				else
					v.Transparency=0
				end
			else
				v.Transparency=1
				if v.Light.Enabled then
					v.Material=Enum.Material.Neon
				else
					v.Material=Enum.Material.Sand
				end
			end
		end
	end
end)

game.Lighting.Changed:connect(Auto)
Auto()
