--Please do not touch anything below unless you know what you're doing.

script.Parent.Parent:WaitForChild("CarSeat")
local seat = script.Parent.Parent.CarSeat.Value

local _,_ = pcall(function() seat.LightInd:Destroy() end)
local _,_ = pcall(function() seat.relay:Destroy() end)
local _,_ = pcall(function() seat.Hazards:Destroy() end)
local _,_ = pcall(function() seat.Left:Destroy() end)
local _,_ = pcall(function() seat.Right:Destroy() end)

wait()

local bool = Instance.new("BoolValue",seat)
bool.Name = "LightInd"
bool.Value = false

local InputService = game:GetService("UserInputService")

local relay = script.Parent.relay:Clone()
relay.Script.Disabled = false
relay.Parent = seat

local left = false
local right = false
local hazards = false
local hibeam = false
local lobeam = false
local lagdebL = false
local lagdebR = false
local lagdebH = false

local fli = {}
local fri = {}
local rli = {}
local rri = {}
local hll = {}
local hlh = {}
local bl = {}
local rrl = {}
local rl = {}

local sl = {{seat.Parent.Lfl.hl,seat.Parent.Lfl.ind},{seat.Parent.Lfr.hl,seat.Parent.Lfr.ind},{seat.Parent.Lrl.Br,seat.Parent.Lrl.ind,seat.Parent.Lrl.Rev},{seat.Parent.Lrr.Br,seat.Parent.Lrr.ind,seat.Parent.Lrr.Rev}}

if not seat:FindFirstChild("Left") then
	local lefts = script.Left:Clone()
	lefts.Parent = seat
	
	local indOn = Instance.new("BrickColorValue",lefts)
	indOn.Name = "indOn"
	indOn.Value = indicatorOn
			
	local indOff = Instance.new("BrickColorValue",lefts)
	indOff.Name = "indOff"
	indOff.Value = indicatorOff
end

if not seat:FindFirstChild("Right") then
	local rights = script.Right:Clone()
	rights.Parent = seat
	
	local indOn = Instance.new("BrickColorValue",rights)
	indOn.Name = "indOn"
	indOn.Value = indicatorOn
			
	local indOff = Instance.new("BrickColorValue",rights)
	indOff.Name = "indOff"
	indOff.Value = indicatorOff
end

if not seat:FindFirstChild("Hazards") then
	local hazardss = script.Hazards:Clone()
	hazardss.Parent = seat
	
	local indOn = Instance.new("BrickColorValue",hazardss)
	indOn.Name = "indOn"
	indOn.Value = indicatorOn
			
	local indOff = Instance.new("BrickColorValue",hazardss)
	indOff.Name = "indOff"
	indOff.Value = indicatorOff
end

function DealWithInput(input)
	if input.KeyCode == Enum.KeyCode.Z and input.UserInputState == Enum.UserInputState.Begin then
		if relay.Value then repeat wait() until not relay.Value end
		left = not left; right = false; hazards = false
		while left do wait()
			if relay.Value and (not lagdebL) then
				lagdebL = true
				for _,i in pairs(fli) do
					i.BrickColor = indicatorOn
					i.Material = Enum.Material.Neon
				end
				for _,i in pairs(rli) do
					i.BrickColor = indicatorOn
					i.Material = Enum.Material.Neon
				end
				sl[1][2].Enabled = true
				sl[3][2].Enabled = true
				script.Parent.Parent.StockUI.Right.TurnSignals.Left.ImageTransparency = 0
				script.Parent.Tick.PlaybackSpeed = 1.4
				script.Parent.Tick:Play()
			end
			if not relay.Value and (lagdebL) then
				lagdebL = false
				for _,i in pairs(fli) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				for _,i in pairs(rli) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				sl[1][2].Enabled = false
				sl[3][2].Enabled = false
				script.Parent.Parent.StockUI.Right.TurnSignals.Left.ImageTransparency = 0.7
				script.Parent.Tick.PlaybackSpeed = 1.2
				script.Parent.Tick:Play()
			end
			if not left then
				lagdebL = false
				for _,i in pairs(fli) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				for _,i in pairs(rli) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				sl[1][2].Enabled = false
				sl[3][2].Enabled = false
				script.Parent.Parent.StockUI.Right.TurnSignals.Left.ImageTransparency = 0.7
				script.Parent.Tick.PlaybackSpeed = 1.2
				script.Parent.Tick:Play()
			break end
		end
	elseif input.KeyCode == Enum.KeyCode.X and input.UserInputState == Enum.UserInputState.Begin then
		if relay.Value then repeat wait() until not relay.Value end
		hazards = not hazards
		if hazards then left = false right = false end
		while hazards do wait()
			if relay.Value and (not lagdebH) then
				lagdebH = true
				for _,i in pairs(fli) do
					i.BrickColor = indicatorOn
					i.Material = Enum.Material.Neon
				end
				for _,i in pairs(fri) do
					i.BrickColor = indicatorOn
					i.Material = Enum.Material.Neon
				end
				for _,i in pairs(rli) do
					i.BrickColor = indicatorOn
					i.Material = Enum.Material.Neon
				end
				for _,i in pairs(rri) do
					i.BrickColor = indicatorOn
					i.Material = Enum.Material.Neon
				end
				sl[1][2].Enabled = true
				sl[2][2].Enabled = true
				sl[3][2].Enabled = true
				sl[4][2].Enabled = true
				script.Parent.Parent.StockUI.Right.TurnSignals.Left.ImageTransparency = 0
				script.Parent.Parent.StockUI.Right.TurnSignals.Right.ImageTransparency = 0
				script.Parent.Tick.PlaybackSpeed = 1.4
				script.Parent.Tick:Play()
			end
			if not relay.Value and (lagdebH) then
				lagdebH = false
				for _,i in pairs(fli) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				for _,i in pairs(fri) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				for _,i in pairs(rli) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				for _,i in pairs(rri) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				sl[1][2].Enabled = false
				sl[2][2].Enabled = false
				sl[3][2].Enabled = false
				sl[4][2].Enabled = false
				script.Parent.Parent.StockUI.Right.TurnSignals.Left.ImageTransparency = 0.7
				script.Parent.Parent.StockUI.Right.TurnSignals.Right.ImageTransparency = 0.7
				script.Parent.Tick.PlaybackSpeed = 1.2
				script.Parent.Tick:Play()
			end
			if not hazards then
				lagdebH = false
				for _,i in pairs(fli) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				for _,i in pairs(fri) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				for _,i in pairs(rli) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				for _,i in pairs(rri) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				sl[1][2].Enabled = false
				sl[2][2].Enabled = false
				sl[3][2].Enabled = false
				sl[4][2].Enabled = false
				script.Parent.Parent.StockUI.Right.TurnSignals.Left.ImageTransparency = 0.7
				script.Parent.Parent.StockUI.Right.TurnSignals.Right.ImageTransparency = 0.7
				script.Parent.Tick.PlaybackSpeed = 1.2
				script.Parent.Tick:Play()
			break end
		end
	elseif input.KeyCode == Enum.KeyCode.C and input.UserInputState == Enum.UserInputState.Begin then
		if relay.Value then repeat wait() until not relay.Value end
		right = not right; left = false; hazards = false
		while right do wait()
			if relay.Value and (not lagdebR) then
				lagdebR = true
				for _,i in pairs(fri) do
					i.BrickColor = indicatorOn
					i.Material = Enum.Material.Neon
				end
				for _,i in pairs(rri) do
					i.BrickColor = indicatorOn
					i.Material = Enum.Material.Neon
				end
				sl[2][2].Enabled = true
				sl[4][2].Enabled = true
				script.Parent.Parent.StockUI.Right.TurnSignals.Right.ImageTransparency = 0
				script.Parent.Tick.PlaybackSpeed = 1.4
				script.Parent.Tick:Play()
			end
			if not relay.Value and (lagdebR) then
				lagdebR = false
				for _,i in pairs(fri) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				for _,i in pairs(rri) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				sl[2][2].Enabled = false
				sl[4][2].Enabled = false
				script.Parent.Parent.StockUI.Right.TurnSignals.Right.ImageTransparency = 0.7
				script.Parent.Tick.PlaybackSpeed = 1.2
				script.Parent.Tick:Play()
			end
			if not right then
				lagdebR = false
				for _,i in pairs(fri) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				for _,i in pairs(rri) do
					i.BrickColor = indicatorOff
					i.Material = Enum.Material.SmoothPlastic
				end
				sl[2][2].Enabled = false
				sl[4][2].Enabled = false
				script.Parent.Parent.StockUI.Right.TurnSignals.Right.ImageTransparency = 0.7
				script.Parent.Tick.PlaybackSpeed = 1.2
				script.Parent.Tick:Play()
			break end
		end
	elseif input.KeyCode == Enum.KeyCode.L and input.UserInputState == Enum.UserInputState.Begin then
		if not lobeam and not hibeam then
			lobeam = true
		elseif lobeam and not hibeam then
			hibeam = true
		else
			lobeam = false
			hibeam = false
		end
		for _,i in pairs(hll) do
			if lobeam then
				i.BrickColor = headlightLow
				i.Material = Enum.Material.Neon
				sl[1][1].Enabled = true
				sl[2][1].Enabled = true
				script.Parent.Parent.StockUI.Right.WarningLights.LoBeam.ImageTransparency = 0
			else
				i.BrickColor = headlightOff
				i.Material = Enum.Material.SmoothPlastic
				sl[1][1].Enabled = false
				sl[2][1].Enabled = false
				script.Parent.Parent.StockUI.Right.WarningLights.LoBeam.ImageTransparency = 0.7
			end
		end
		for _,i in pairs(hlh) do
   if hibeam then
    i.BrickColor = headlightHi
    i.Material = Enum.Material.Neon
    script.Parent.Parent.StockUI.Right.WarningLights.HiBeam.ImageTransparency = 0
    sl[1][1].Range = 60
    sl[2][1].Range = 60
   else
    i.BrickColor = headlightOff
    i.Material = Enum.Material.SmoothPlastic
    script.Parent.Parent.StockUI.Right.WarningLights.HiBeam.ImageTransparency = 0.7
    sl[1][1].Range = 30
    sl[2][1].Range = 30
   end
  end
		for _,i in pairs(hlh) do
			if hibeam then
				i.BrickColor = headlightHi
				i.Material = Enum.Material.Neon
				script.Parent.Parent.StockUI.Right.WarningLights.HiBeam.ImageTransparency = 0
			else
				i.BrickColor = headlightOff
				i.Material = Enum.Material.SmoothPlastic
				script.Parent.Parent.StockUI.Right.WarningLights.HiBeam.ImageTransparency = 0.7
			end
		end
		for _,i in pairs(rrl) do
			if lobeam then
				i.BrickColor = rearrunOn
				i.Material = Enum.Material.Neon
			else
				i.BrickColor = rearrunOff
				i.Material = Enum.Material.SmoothPlastic
			end
		end
	elseif input.KeyCode == Enum.KeyCode.S then
		if input.UserInputState == Enum.UserInputState.Begin then
			for _,i in pairs(bl) do
				i.BrickColor = brakelightOn
				i.Material = Enum.Material.Neon
				sl[3][1].Enabled = true
				sl[4][1].Enabled = true
			end
		else
			for _,i in pairs(bl) do
				i.BrickColor = brakelightOff
				i.Material = Enum.Material.SmoothPlastic
				sl[3][1].Enabled = false
				sl[4][1].Enabled = false
			end
		end
	elseif input.KeyCode == Enum.KeyCode.Q and input.UserInputState == Enum.UserInputState.Begin then
		if script.Parent.Parent.Storage.CurrentGear.Value == 2 then
			for _,i in pairs(rl) do
				i.BrickColor = reverseOn
				i.Material = Enum.Material.Neon
				sl[3][3].Enabled = true
				sl[4][3].Enabled = true
			end
		else
			for _,i in pairs(rl) do
				i.BrickColor = reverseOff
				i.Material = Enum.Material.SmoothPlastic
				sl[3][3].Enabled = false
				sl[4][3].Enabled = false
			end
		end
	elseif input.KeyCode == Enum.KeyCode.E and input.UserInputState == Enum.UserInputState.Begin then
		if script.Parent.Parent.Storage.CurrentGear.Value == 2 then
			for _,i in pairs(rl) do
				i.BrickColor = reverseOn
				i.Material = Enum.Material.Neon
				sl[3][3].Enabled = true
				sl[4][3].Enabled = true
			end
		else
			for _,i in pairs(rl) do
				i.BrickColor = reverseOff
				i.Material = Enum.Material.SmoothPlastic
				sl[3][3].Enabled = false
				sl[4][3].Enabled = false
			end
		end
	end
end