--UIS.InputEnded:Connect(function(key)
--	if key.KeyCode == Flash then
--		flashing = false
--		if not Popups_Enabled then
--			if parklightActive then
--				LightEvent:FireServer("Headlights", 0, Fade_Time, tabG, Light_Type, Popups_Enabled)
--			else
--				LightEvent:FireServer("Headlights", HL.Value, Fade_Time, tabG, Light_Type, Popups_Enabled)
--			end
--		else
--			if parklightActive then
--				LightEvent:FireServer("PopupLights", 0, Fade_Time, tabG, Light_Type, Popups_Enabled)
--			else
--				LightEvent:FireServer("PopupLights", HL.Value, Fade_Time, tabG, Light_Type, Popups_Enabled)
--			end
--		end	
--	end
--end)


LightEvent:FireServer("Setup", Low_Beam_Color, High_Beam_Color, Running_Light_Color, Front_Indicator_Color, Rear_Indicator_Color, Fog_Light_Color, Popups_Enabled, Plate_Lights, Plate_Light_Color, Trunk_Lights, Mirror_Indicators, Running_Light_Location, Fade_Time, Indicator_Flash_Rate, Interior_Lights, Interior_Light_Color, Door_Functionality)

autoLight()
brakes()
reverse()

UIS.InputBegan:Connect(input)
DriveSeat.ChildAdded:Connect(autoLight)
DriveSeat.ChildRemoved:Connect(leavedriveseat)
Values.Brake.Changed:Connect(brakes)
Values.Gear.Changed:Connect(reverse)

local co2 = coroutine.create(function()
	while wait() do
		if Sequential_Indicators then
			if LI.Value then
				RI.Value = false
				H.Value = false
				script.ClickOn:Play()
				TweenService:Create(script.Parent.LeftInd, indgui_tweeninfo, {ImageTransparency = 0}):Play()
				for i = 1, Sequential_Segments do
					LightEvent:FireServer("SignalLeft", 0, 0.02, Indicator_Type, Sequential_Indicators, i)
					wait(Indicator_Flash_Rate / Sequential_Segments)
				end
				wait(0.1)
				script.ClickOff:Play()
				TweenService:Create(script.Parent.LeftInd, indgui_tweeninfo, {ImageTransparency = 1}):Play()
				LightEvent:FireServer("SignalLeft", 0, 1, Indicator_Type, Sequential_Indicators, 1)	
				wait(Indicator_Flash_Rate)
			else
				LightEvent:FireServer("SignalLeft", 0, 1, Indicator_Type, Sequential_Indicators, 1)
			end
			if RI.Value then
				LI.Value = false
				H.Value = false
				script.ClickOn:Play()
				TweenService:Create(script.Parent.RightInd, indgui_tweeninfo, {ImageTransparency = 0}):Play()
				for i = 1, Sequential_Segments do
					LightEvent:FireServer("SignalRight", 0, 0.02, Indicator_Type, Sequential_Indicators, i)
					wait(Indicator_Flash_Rate / Sequential_Segments)
				end
				wait(0.1)
				script.ClickOff:Play()
				TweenService:Create(script.Parent.RightInd, indgui_tweeninfo, {ImageTransparency = 1}):Play()
				LightEvent:FireServer("SignalRight", 0, 1, Indicator_Type, Sequential_Indicators, 1)	
				wait(Indicator_Flash_Rate)
			else
				LightEvent:FireServer("SignalRight", 0, 1, Indicator_Type, Sequential_Indicators, 1)
			end
			if H.Value then
				LI.Value = false
				RI.Value = false
				script.ClickOn:Play()
				TweenService:Create(script.Parent.LeftInd, indgui_tweeninfo, {ImageTransparency = 0}):Play()
				TweenService:Create(script.Parent.RightInd, indgui_tweeninfo, {ImageTransparency = 0}):Play()
				for i = 1, Sequential_Segments do
					LightEvent:FireServer("Hazards", 0, 0.02, Indicator_Type, Sequential_Indicators, i)
					wait(Indicator_Flash_Rate / Sequential_Segments)
				end
				wait(0.1)
				script.ClickOff:Play()
				TweenService:Create(script.Parent.LeftInd, indgui_tweeninfo, {ImageTransparency = 1}):Play()
				TweenService:Create(script.Parent.RightInd, indgui_tweeninfo, {ImageTransparency = 1}):Play()
				LightEvent:FireServer("Hazards", 0, 1, Indicator_Type, Sequential_Indicators, 1)	
				wait(Indicator_Flash_Rate)
			else
				LightEvent:FireServer("Hazards", 0, 1, Indicator_Type, Sequential_Indicators, 1)
			end
		end
	end
end)

local co = coroutine.create(function()
	while wait() do
		if not Sequential_Indicators then
			if LI.Value then
				RI.Value = false
				H.Value = false
				script.ClickOn:Play()
				TweenService:Create(script.Parent.LeftInd, indgui_tweeninfo, {ImageTransparency = 0}):Play()
				LightEvent:FireServer("SignalLeft", 1, 0.02, Indicator_Type)
				wait(Indicator_Flash_Rate)
				script.ClickOff:Play()
				TweenService:Create(script.Parent.LeftInd, indgui_tweeninfo, {ImageTransparency = 1}):Play()
				if Running_Light_Location == "Low Beam / Indicators" and parklightActive then
					LightEvent:FireServer("SignalLeft", 0, 0.71, Indicator_Type)	
				else
					LightEvent:FireServer("SignalLeft", 0, 1, Indicator_Type)	
				end
				wait(Indicator_Flash_Rate)
			else
				TweenService:Create(script.Parent.LeftInd, indgui_tweeninfo, {ImageTransparency = 1}):Play()
				if Running_Light_Location == "Low Beam / Indicators" and parklightActive then
					LightEvent:FireServer("SignalLeft", 0, 0.71, Indicator_Type)	
				else
					LightEvent:FireServer("SignalLeft", 0, 1, Indicator_Type)	
				end	
			end	
			if RI.Value then
				LI.Value = false
				H.Value = false
				script.ClickOn:Play()
				TweenService:Create(script.Parent.RightInd, indgui_tweeninfo, {ImageTransparency = 0}):Play()
				LightEvent:FireServer("SignalRight", 1, 0.02, Indicator_Type)
				wait(Indicator_Flash_Rate)
				script.ClickOff:Play()
				TweenService:Create(script.Parent.RightInd, indgui_tweeninfo, {ImageTransparency = 1}):Play()
				if Running_Light_Location == "Indicators" and parklightActive then
					LightEvent:FireServer("SignalRight", 0, 0.71, Indicator_Type)	
				else
					LightEvent:FireServer("SignalRight", 0, 1, Indicator_Type)	
				end
				wait(Indicator_Flash_Rate)
			else
				TweenService:Create(script.Parent.RightInd, indgui_tweeninfo, {ImageTransparency = 1}):Play()
				if Running_Light_Location == "Low Beam / Indicators" and parklightActive then
					LightEvent:FireServer("SignalRight", 0, 0.71, Indicator_Type)	
				else
					LightEvent:FireServer("SignalRight", 0, 1, Indicator_Type)	
				end	
			end		
			if H.Value then
				LI.Value = false
				RI.Value = false
				script.ClickOn:Play()
				TweenService:Create(script.Parent.LeftInd, indgui_tweeninfo, {ImageTransparency = 0}):Play()
				TweenService:Create(script.Parent.RightInd, indgui_tweeninfo, {ImageTransparency = 0}):Play()
				LightEvent:FireServer("Hazards", 1, 0.02, Indicator_Type)
				wait(Indicator_Flash_Rate)
				script.ClickOff:Play()
				TweenService:Create(script.Parent.LeftInd, indgui_tweeninfo, {ImageTransparency = 1}):Play()
				TweenService:Create(script.Parent.RightInd, indgui_tweeninfo, {ImageTransparency = 1}):Play()
				if Running_Light_Location == "Low Beam / Indicators" and parklightActive then
					LightEvent:FireServer("Hazards", 0, 0.71, Indicator_Type)	
				else
					LightEvent:FireServer("Hazards", 0, 1, Indicator_Type)	
				end	
				wait(Indicator_Flash_Rate)				
			else
				TweenService:Create(script.Parent.LeftInd, indgui_tweeninfo, {ImageTransparency = 1}):Play()
				TweenService:Create(script.Parent.RightInd, indgui_tweeninfo, {ImageTransparency = 1}):Play()
				if Running_Light_Location == "Low Beam / Indicators" and parklightActive then
					LightEvent:FireServer("Hazards", 0, 0.71, Indicator_Type)	
				else
					LightEvent:FireServer("Hazards", 0, 1, Indicator_Type)	
				end	
			end
		end
	end
end)	
coroutine.resume(co)
coroutine.resume(co2)
