--Made by Repressed_Memories
-- Edited by Truenus


local component = script.Parent.Parent
local car = script.Parent.Parent.Parent.Parent.Car.Value
local mouse = game.Players.LocalPlayer:GetMouse()
local leftsignal = "z"
local rightsignal = "c"
local hazards = "x"
local hazardson = false
local lefton = false
local righton = false
local leftlight = car.Body.Lights.Left.RLTS.TSL
local rightlight = car.Body.Lights.Right.RRTS.TSL
local leftfront = car.Body.Lights.Left.RLTS
local rightfront = car.Body.Lights.Right.RRTS
local signalblinktime = 0.32
local neonleft = car.Body.Lights.Left.LTS
local neonright = car.Body.Lights.Right.RTS
local leftgui = script.Parent.Parent.Parent.Parent:WaitForChild("AC6_Stock_Gauges").Left
local rightgui = script.Parent.Parent.Parent.Parent:WaitForChild("AC6_Stock_Gauges").Right
local off =  BrickColor.New("Mid gray")
local on = BrickColor.New("Bright orange")
mouse.KeyDown:connect(function(lkey)
	local key = string.lower(lkey)
	if key == leftsignal then
		if lefton == false then
			lefton = true
			script.Parent.Parent.StartSignal:play()
			repeat
				neonleft.BrickColor=on
				leftlight.Enabled = true
				neonleft.Material = "Neon"
				neonleft.Transparency=0
				leftgui.ImageTransparency=0
				leftfront.Material = "Neon"
				component.TurnSignal:play()
				wait(signalblinktime)
				neonleft.Transparency=1
				neonleft.BrickColor=off
				leftgui.ImageTransparency=1
				component.TurnSignal:play()
				neonleft.Material = "Sand"
				leftfront.Material = "Sand"
				leftlight.Enabled = false
				wait(signalblinktime)
			until
			lefton == false or righton == true
		elseif lefton == true or righton == true then
			lefton = false
			component.TurnSignal:stop()
			leftlight.Enabled = false
			wait(0.05)
			script.Parent.Parent.StopSignal:play()
		end
	elseif key == rightsignal then
		if righton == false then
			righton = true
			script.Parent.Parent.StartSignal:play()
			repeat
				rightlight.Enabled = true
				neonright.Material = "Neon"
				rightfront.Material = "Neon"
				component.TurnSignal:play()
				neonright.BrickColor=on
				neonright.Transparency=0
				rightgui.ImageTransparency=0
				wait(signalblinktime)
				neonright.Transparency=1
				neonright.BrickColor=off
				rightgui.ImageTransparency=1
				component.TurnSignal:play()
				neonright.Material = "Sand"
				rightfront.Material = "Sand"
				rightlight.Enabled = false
				wait(signalblinktime)
			until
			righton == false or lefton == true
		elseif righton == true or lefton == true then
			righton = false
			component.TurnSignal:stop()
			wait(0.05)
			script.Parent.Parent.StopSignal:play()
			rightlight.Enabled = false
		end
	elseif key == hazards then
		if hazardson == false then
			script.Parent.Parent.StartSignal:play()
			hazardson = true
			repeat
				neonright.BrickColor=on
				neonleft.BrickColor=on
				neonright.Material = "Neon"
				rightfront.Material = "Neon"
				neonleft.Material = "Neon"
				neonleft.Transparency=0
				neonright.Transparency=0
				leftfront.Material = "Neon"
				component.TurnSignal:play()
				rightlight.Enabled = true
				leftlight.Enabled = true
				leftgui.ImageTransparency=0
				rightgui.ImageTransparency=0
				wait(signalblinktime)
				neonleft.Transparency=1
				neonright.Transparency=1
				neonright.BrickColor=off
				neonleft.BrickColor=off
				leftgui.ImageTransparency=1
				rightgui.ImageTransparency=1
				component.TurnSignal:play()
				neonright.Material = "Sand"
				rightfront.Material = "Sand"
				neonleft.Material = "Sand"
				leftfront.Material = "Sand"
				rightlight.Enabled = false
				leftlight.Enabled = false
				wait(signalblinktime)
			until
			hazardson == false
		elseif hazardson == true then
			hazardson = false
			component.TurnSignal:stop()
			rightlight.Enabled = false
			leftlight.Enabled = false
			wait(0.05)
			script.Parent.Parent.StopSignal:play()
		end
	end
end)