I have a script that, when a button is pressed, turns off all parts named LIGHTS and turns on a rotating emergency light. It also makes a rotating engine part stop, but I do not need that function anymore. The issue is, pressing the button does not turn it off. How would I go about making it that way?

Here is the full script:

local PowerOn = true
local PowerButton = game:GetService("Workspace").PowerButton.PowerShutoff.Detect
local PowerValue = game:GetService("Workspace").Power

local Rotation = 0.1

local Debounce = false

PowerButton.MouseClick:connect(function(Player)
	if not Debounce and Player.Team == (game:GetService("Teams"):WaitForChild("Team") or game:GetService("Teams"):WaitForChild("Security [C-Beta]")) or Player.Team == (game:GetService("Teams"):WaitForChild("Team2") or game:GetService("Teams"):WaitForChild("Team3")) then
		if PowerOn then
			Debounce = true
			for Index,Obj in pairs(game:GetService("Workspace"):GetChildren()) do
				if Obj.Name == "LIGHT" then
					local Light = Obj:WaitForChild("PointLight")
					Light.Enabled = false
				end
			end
			for Index,Obj in pairs(workspace:GetChildren()) do
				if Obj:IsA("Model") and Obj.Name == "EmergencyLight" then
					local RotPart = Obj:WaitForChild("Rotate")
					RotPart.SpotLight.Enabled = true
				elseif Obj:IsA("Model") and Obj.Name == "Alarm" then
					Obj.music:Stop()
				end
			end
			PowerOn = false
			PowerValue.Value = false
			game:GetService("Workspace"):WaitForChild("Engine"):WaitForChild("EngineMoving"):WaitForChild("TURN").RightParamB = 0
			for Index,Obj in pairs(workspace.SOUNDPIECES:GetChildren()) do
				Obj.Sound:Stop()
			end
			delay(60, function()
				Debounce = false
			end)
		else
			Debounce = true
			for Index,Obj in pairs(game:GetService("Workspace"):GetChildren()) do
				if Obj.Name == "LIGHT" then
					local Light = Obj:WaitForChild("PointLight")
					Light.Enabled = true
				end
			end
			for Index,Obj in pairs(workspace:GetChildren()) do
				if Obj:IsA("Model") and Obj.Name == "EmergencyLight" then
					local RotPart = Obj:WaitForChild("Rotate")
					RotPart.SpotLight.Enabled = false
				end
			end
			PowerOn = true
			PowerValue.Value = true
			for Index,Obj in pairs(workspace.SOUNDPIECES:GetChildren()) do
				Obj.Sound:Play()
			end
			game:GetService("Workspace"):WaitForChild("Engine"):WaitForChild("EngineMoving"):WaitForChild("TURN").RightParamB = 0.5
			delay(2,function()
				game:GetService("Workspace"):WaitForChild("Engine"):WaitForChild("EngineMoving"):WaitForChild("TURN").RightParamB = 0.25
			end)
			delay(60, function()
				Debounce = false
			end)
		end
	end
end)

game:GetService("RunService").Stepped:connect(function()
	if not PowerOn then
		for Index,Obj in pairs(workspace:GetChildren()) do
			if Obj:IsA("Model") and Obj.Name == "EmergencyLight" then
				local RotPart = Obj:WaitForChild("Rotate")
				RotPart.CFrame = RotPart.CFrame * CFrame.Angles(Rotation,0,0)
			end
		end
	end
end)

2 comments

0

script.Disabled = true

0

Where would I add that into the script?