function AlarmFlash()if aflash then return end aflash=true while alarmpiezo do trans.AlarmLED.BrickColor=BrickColor.new("\082\101\097\108\108\121 \114\101\100")wait(.1)trans.AlarmLED.BrickColor=BrickColor.new("\077\105\100 \103\114\097\121")wait(.1)end aflash=false if#system.ActiveAlarms:GetChildren()>0 then trans.AlarmLED.BrickColor=BrickColor.new("\082\101\097\108\108\121 \114\101\100")end end function TroFlash()if tflash then return end tflash=true while tropiezo do trans.TroubleLED.BrickColor=BrickColor.new("\068\101\101\112 \111\114\097\110\103\101")wait(.1)trans.TroubleLED.BrickColor=BrickColor.new("\077\105\100 \103\114\097\121")wait(.1)end tflash=false if#system.Troubles:GetChildren()>0 then trans.TroubleLED.BrickColor=BrickColor.new("\068\101\101\112 \111\114\097\110\103\101")end end function ResetLED()if system.Reset.Value==false then return end trans.Sounder.T3.Disabled=true trans.Sounder.TR.Disabled=true alarmpiezo=false tropiezo=false while system.Reset.Value==true do trans.AlarmLED.BrickColor=BrickColor.new("\082\101\097\108\108\121 \114\101\100")trans.TroubleLED.BrickColor=BrickColor.new("\068\101\101\112 \111\114\097\110\103\101")trans.SilencedLED.BrickColor=BrickColor.new("\068\101\101\112 \111\114\097\110\103\101")wait()end trans.AlarmLED.BrickColor=BrickColor.new("\077\105\100 \103\114\097\121")trans.TroubleLED.BrickColor=BrickColor.new("\077\105\100 \103\114\097\121")trans.SilencedLED.BrickColor=BrickColor.new("\077\105\100 \103\114\097\121")CheckForAlarmAck()CheckForTroAck()end system.Reset.Changed:connect(ResetLED)function CheckForAlarmAck()local Z=system.ActiveAlarms:GetChildren()local N=true for Q=1,#Z,1 do if Z[Q]:findFirstChild("\065\099\107")==nil then N=false end end if N then alarmpiezo=false else alarmpiezo=true end if alarmpiezo then trans.Sounder.T3.Disabled=false trans.Sounder.TR.Disabled=true elseif tropiezo then trans.Sounder.T3.Disabled=true trans.Sounder.TR.Disabled=false elseif alarmpiezo==false and tropiezo==false then trans.Sounder.T3.Disabled=true trans.Sounder.TR.Disabled=true end AlarmFlash()TroFlash()end function CheckForTroAck()local Z=system.Troubles:GetChildren()local N=true for Q=1,#Z,1 do if Z[Q]:findFirstChild("\065\099\107")==nil then N=false end end if N then tropiezo=false else tropiezo=true end if alarmpiezo then trans.Sounder.T3.Disabled=false trans.Sounder.TR.Disabled=true elseif tropiezo then trans.Sounder.T3.Disabled=true trans.Sounder.TR.Disabled=false elseif alarmpiezo==false and tropiezo==false then trans.Sounder.T3.Disabled=true trans.Sounder.TR.Disabled=true end AlarmFlash()TroFlash()if#Z==0 then trans.TroubleLED.BrickColor=BrickColor.new("\077\105\100 \103\114\097\121")end end function NewAlarm(Z)alarmpiezo=true Z.ChildAdded:connect(function()CheckForAlarmAck()end)if alarmpiezo then trans.Sounder.T3.Disabled=false trans.Sounder.TR.Disabled=true elseif tropiezo then trans.Sounder.T3.Disabled=true trans.Sounder.TR.Disabled=false elseif alarmpiezo==false and tropiezo==false then trans.Sounder.T3.Disabled=true trans.Sounder.TR.Disabled=true end AlarmFlash()TroFlash()end system.ActiveAlarms.ChildAdded:connect(NewAlarm)system.ActiveAlarms.ChildRemoved:connect(CheckForAlarmAck)function NewTrouble(Z)tropiezo=true Z.ChildAdded:connect(function()CheckForTroAck()end)if alarmpiezo then trans.Sounder.T3.Disabled=false trans.Sounder.TR.Disabled=true elseif tropiezo then trans.Sounder.T3.Disabled=true trans.Sounder.TR.Disabled=false elseif alarmpiezo==false and tropiezo==false then trans.Sounder.T3.Disabled=true trans.Sounder.TR.Disabled=true end AlarmFlash()TroFlash()end system.Troubles.ChildAdded:connect(NewTrouble)system.Troubles.ChildRemoved:connect(CheckForTroAck)system.Silence.Changed:connect(function()if system.Silence.Value==true then trans.SilencedLED.BrickColor=BrickColor.new("\068\101\101\112 \111\114\097\110\103\101")else trans.SilencedLED.BrickColor=BrickColor.new("\077\105\100 \103\114\097\121")end end)
-- Main LEDs

function AlarmFlash()
	if aflash then
		return
	end
	aflash = true
	while alarmpiezo do
		trans.AlarmLED.BrickColor = BrickColor.new("Really red")
		wait(0.1)
		trans.AlarmLED.BrickColor = BrickColor.new("Mid gray")
		wait(0.1)
	end
	aflash = false
	if #system.ActiveAlarms:GetChildren() > 0 then
		trans.AlarmLED.BrickColor = BrickColor.new("Really red")
	end
end

function TroFlash()
	if tflash then
		return
	end
	tflash = true
	while tropiezo do
		trans.TroubleLED.BrickColor = BrickColor.new("Deep orange")
		wait(0.1)
		trans.TroubleLED.BrickColor = BrickColor.new("Mid gray")
		wait(0.1)
	end
	tflash = false
	if #system.Troubles:GetChildren() > 0 then
		trans.TroubleLED.BrickColor = BrickColor.new("Deep orange")
	end
end

function ResetLED()
	if system.Reset.Value == false then
		return
	end
	trans.Sounder.T3.Disabled = true
	trans.Sounder.TR.Disabled = true
	alarmpiezo = false
	tropiezo = false
	while system.Reset.Value == true do
		trans.AlarmLED.BrickColor = BrickColor.new("Really red")
		trans.TroubleLED.BrickColor = BrickColor.new("Deep orange")
		trans.SilencedLED.BrickColor = BrickColor.new("Deep orange")
		wait()
	end
	trans.AlarmLED.BrickColor = BrickColor.new("Mid gray")
	trans.TroubleLED.BrickColor = BrickColor.new("Mid gray")
	trans.SilencedLED.BrickColor = BrickColor.new("Mid gray")
	CheckForAlarmAck()
	CheckForTroAck()
end

system.Reset.Changed:connect(ResetLED)

function CheckForAlarmAck()
	local af = system.ActiveAlarms:GetChildren()
	local aack = true
	for i = 1, #af do
		if af[i]:findFirstChild("Ack") == nil then
			aack = false
		end
	end
	if aack then
		alarmpiezo = false
	else
		alarmpiezo = true
	end
	if alarmpiezo then
		trans.Sounder.T3.Disabled = false
		trans.Sounder.TR.Disabled = true
	elseif tropiezo then
		trans.Sounder.T3.Disabled = true
		trans.Sounder.TR.Disabled = false
	elseif alarmpiezo == false and tropiezo == false then
		trans.Sounder.T3.Disabled = true
		trans.Sounder.TR.Disabled = true
	end
	AlarmFlash()
	TroFlash()
end

function CheckForTroAck()
	local tf = system.Troubles:GetChildren()
	local tack = true
	for i = 1, #tf do
		if tf[i]:findFirstChild("Ack") == nil then
			tack = false
		end
	end
	if tack then
		tropiezo = false
	else
		tropiezo = true
	end
	if alarmpiezo then
		trans.Sounder.T3.Disabled = false
		trans.Sounder.TR.Disabled = true
	elseif tropiezo then
		trans.Sounder.T3.Disabled = true
		trans.Sounder.TR.Disabled = false
	elseif alarmpiezo == false and tropiezo == false then
		trans.Sounder.T3.Disabled = true
		trans.Sounder.TR.Disabled = true
	end
	AlarmFlash()
	TroFlash()
	if #tf == 0 then
		trans.TroubleLED.BrickColor = BrickColor.new("Mid gray")
	end
end

function NewAlarm(na)
	alarmpiezo = true
	na.ChildAdded:connect(function()
		CheckForAlarmAck()
	end)
	if alarmpiezo then
		trans.Sounder.T3.Disabled = false
		trans.Sounder.TR.Disabled = true
	elseif tropiezo then
		trans.Sounder.T3.Disabled = true
		trans.Sounder.TR.Disabled = false
	elseif alarmpiezo == false and tropiezo == false then
		trans.Sounder.T3.Disabled = true
		trans.Sounder.TR.Disabled = true
	end
	AlarmFlash()
	TroFlash()
end

system.ActiveAlarms.ChildAdded:connect(NewAlarm)

system.ActiveAlarms.ChildRemoved:connect(CheckForAlarmAck)

function NewTrouble(nt)
	tropiezo = true
	nt.ChildAdded:connect(function()
		CheckForTroAck()
	end)
	if alarmpiezo then
		trans.Sounder.T3.Disabled = false
		trans.Sounder.TR.Disabled = true
	elseif tropiezo then
		trans.Sounder.T3.Disabled = true
		trans.Sounder.TR.Disabled = false
	elseif alarmpiezo == false and tropiezo == false then
		trans.Sounder.T3.Disabled = true
		trans.Sounder.TR.Disabled = true
	end
	AlarmFlash()
	TroFlash()
end

system.Troubles.ChildAdded:connect(NewTrouble)

system.Troubles.ChildRemoved:connect(CheckForTroAck)

system.Silence.Changed:connect(function()
	if system.Silence.Value == true then
		trans.SilencedLED.BrickColor = BrickColor.new("Deep orange")
	else
		trans.SilencedLED.BrickColor = BrickColor.new("Mid gray")
	end
end)
