[SOLVED] How to Fix PowerOutageEvent

I am trying to make it that the Sound only activates when the Power is (On) and (Off) any idea of how I can achieve this? Because the (On) Sound plays when the Power is off.

Workspace | PowerOutage Script:

-- PowerOutage Script
local Part = script.Parent
local ProximityPrompt = Part:WaitForChild("ProximityPrompt")
local Prompt = script.Parent.ProximityPrompt
local Cooldown = false
local Duration = 25 -- Duration in Seconds.

game.Workspace.PowerBox.Button.ProximityPrompt.Enabled = false

for i, v in pairs(workspace.Map.KillArea.Lights:GetDescendants()) do -- Pairing as an instance.
	task.spawn(function() -- Calling through the Engine's scheduler to function.
		if v:IsA("Model") and v.Name == "LightBulb" then -- Finding the Model associating from the Workspace.
			while true do -- Creating a Loop Statement.

				task.wait(25) -- Waiting 25 seconds then will begin the "PowerOutage".
				v.Bulb.PointLight.Brightness = 0 -- Making the "Lights" Brightness zero (Off).
				v.Light.Transparency = 1 -- Simply making it that the Neon Part is Transparent.
				game.Workspace.BackgroundSound.Ambience:Stop() -- BackgroundSound Sound will (Stop) Playing.
				game.Lighting.Atmosphere.Density = 1 -- Creating the Fog pressure level.
				game.Lighting.Atmosphere.Haze = 10 -- Same Here.
				game.Workspace.Monster.Torso.PointLight.Enabled = true -- Making the Monsters Torso has translucent PointLight when "PowerOutage" is active.
				game.Workspace.PowerBox.Button.ProximityPrompt.Enabled = true
				game.Workspace.PowerBox.Button.Color = Color3.new(0, 0, 0)
				script.PowerOff:Play() -- PowerOff Sound will (Play).
				script.PowerOn:Play() -- PowerOn Sound will (Play).
			
				Prompt.Triggered:Connect(function()
					if Cooldown == false then
						Cooldown = true
						-- task.wait(40) -- Waiting 40 seconds then will stop the "PowerOutage".
						v.Bulb.PointLight.Brightness = 1 -- Making the "Lights" Brightness 1 (On).
						v.Light.Transparency = 0 -- Simply making it that the Neon Part is Non-transparent.
						game.Workspace.BackgroundSound.Ambience:Play() -- BackgroundSound Sound will (Start).
						game.Lighting.Atmosphere.Density = 0 -- Disabling the Fog pressure level.
						game.Lighting.Atmosphere.Haze = 0 -- Same Here.
						game.Workspace.Monster.Torso.PointLight.Enabled = false -- Making the Monsters Torso has Non-translucent PointLight when "PowerOutage" is inactive.
						game.Workspace.PowerBox.Button.ProximityPrompt.Enabled = false
						game.Workspace.PowerBox.Button.Color = Color3.new(0, 161, 0)
						script.PowerOn:Play() -- PowerOn Sound will (Play).
						script.PowerOff:Stop() -- PowerOff Sound will (Stop).
						task.wait(Duration)
						Cooldown = false
					end
				end)
			end
		end
	end)
end

Yes I am aware it is messy I am trying to fix the Script before making it tidy.

Is cooldown whether or not power is on? It would be easier to understand and use this if you had a boolean for power.

You play both the sounds here, is that the issue?

1 Like

I will show you a video of the problem.

1 Like

I would recommend using the following statement for your while loop,

while task.wait() do

end

--- or

while wait(waitime) do

end

That could be the issue if it timesout

1 Like

Basically, to summaries the key factor of the situation this line of code – task.wait(25) -- Waiting 25 seconds then will begin the "PowerOutage". v.Bulb.PointLight.Brightness = 0 -- Making the "Lights" Brightness zero (Off). v.Light.Transparency = 1 -- Simply making it that the Neon Part is Transparent. game.Workspace.BackgroundSound.Ambience:Stop() -- BackgroundSound Sound will (Stop) Playing. game.Lighting.Atmosphere.Density = 1 -- Creating the Fog pressure level. game.Lighting.Atmosphere.Haze = 10 -- Same Here. game.Workspace.Monster.Torso.PointLight.Enabled = true -- Making the Monsters Torso has translucent PointLight when "PowerOutage" is active. game.Workspace.PowerBox.Button.ProximityPrompt.Enabled = true -- Enabling the ProximityPrompt when the Power is (Of). game.Workspace.PowerBox.Button.Color = Color3.new(0, 0, 0) script.PowerOff:Play() -- PowerOff Sound will (Play). script.PowerOn:Play() -- PowerOn Sound will (Play).

Would run when the Power is (Off) and the Power (Off) Sound will play.

I also got this Script here inside of StarterGui interferes with a Local Script

local Theme1 = game.Workspace.PowerBox.Button.PowerOutage.PowerOff
local Theme2 = game.Workspace.PowerBox.Button.PowerOutage.PowerOn
local FlashEffect = script.Parent.StationFrameEffect;
local Camera = workspace.Camera
local ScreenZoomAmount = 0.004
local FlashAmount = 0.001
local ScreenAngelsAmount = 0.005
local StandardFieldOfView = 70

game:GetService("RunService").RenderStepped:Connect(function()
Camera.FieldOfView = StandardFieldOfView - Theme1.PlaybackLoudness * ScreenZoomAmount
FlashEffect.BackgroundTransparency = 1 - Theme1.PlaybackLoudness * FlashAmount
Camera.CFrame = workspace.Camera.CFrame * CFrame.Angles(0, 
   0, math.rad(math.random(- Theme1.PlaybackLoudness,
   Theme1.PlaybackLoudness) * ScreenAngelsAmount)) + Vector3.new(
   math.rad(math.random( - Theme1.PlaybackLoudness * ScreenAngelsAmount,
	 Theme1.PlaybackLoudness * ScreenAngelsAmount) * ScreenAngelsAmount ), 
   math.rad(math.random( - Theme1.PlaybackLoudness * ScreenAngelsAmount,
	 Theme1.PlaybackLoudness * ScreenAngelsAmount) * ScreenAngelsAmount ), 
   math.rad(math.random( - Theme1.PlaybackLoudness * ScreenAngelsAmount,
	 Theme1.PlaybackLoudness * ScreenAngelsAmount) * ScreenAngelsAmount )
	)  
end)


game:GetService("RunService").RenderStepped:Connect(function()
	Camera.FieldOfView = StandardFieldOfView - Theme2.PlaybackLoudness * ScreenZoomAmount
	FlashEffect.BackgroundTransparency = 1 - Theme2.PlaybackLoudness * FlashAmount
	Camera.CFrame = workspace.Camera.CFrame * CFrame.Angles(0, 
		0, math.rad(math.random(- Theme2.PlaybackLoudness,
			Theme2.PlaybackLoudness) * ScreenAngelsAmount)) + Vector3.new(
		math.rad(math.random( - Theme2.PlaybackLoudness * ScreenAngelsAmount,
			Theme2.PlaybackLoudness * ScreenAngelsAmount) * ScreenAngelsAmount ), 
		math.rad(math.random( - Theme2.PlaybackLoudness * ScreenAngelsAmount,
			Theme2.PlaybackLoudness * ScreenAngelsAmount) * ScreenAngelsAmount ), 
		math.rad(math.random( - Theme2.PlaybackLoudness * ScreenAngelsAmount,
			Theme2.PlaybackLoudness * ScreenAngelsAmount) * ScreenAngelsAmount )
	)  
end)

It is nothing so serious it shakes the Players Screen when the Sounds are activated.

In the bottom of this code you play Power on sound and power off. Why? I thought that was your issue.

Side-note, I really recommend restructuring the script with a boolean for Power, it will be much easier to use.

--switch line for power changing
--use this when prompt is activated and call a function that checks the value and carries out correct lines
if Power then Power = false else Power = true end
1 Like

I am not that god at Scripting though so I wouldn’t have a clue of how to do that.

Do you have Discord at any chance I can just stream the issue there.

Actually scrap that I am making a video.

I can’t use my computer right now, so I can’t help massively, but it would look something like this:

local Power = true -- true is on, false is off

local function powerChange(onoff)
      if onoff == true then
             --anything when power is on
      if onoff == false then
             --anything when power is off
end

prompt.Activated:Connect()
     if Power == true then Power = False else Power = true end
     powerChange(Power)
end

please answer why you play the power On sound at the same time as the power Off sound in the script above!

1 Like

Here is the video that is providing me issue, when you would to watch the video you can see the Power (Off) Sound function when the Power is already (Off).

Do you intend to have both play at the start?

2 Likes

I have just fixed that my bad.

So with the video you just saw can you dedicate of what my problem is. Power (Off) Sound plays amongst the Power Outage and I only want the Sound to play when the Power itself turns (Off). The Sound does not play during the Power Outage Event.

I tried to organize it a bit, not sure if there are errors, so basically,
Keep the stuff that happens per individual light, all inside its own loop
Don’t put the prompt detect or the game.lighting stuff in the same loop

-- PowerOutage Script
local Part = script.Parent
local ProximityPrompt = Part:WaitForChild("ProximityPrompt")
local Prompt = script.Parent.ProximityPrompt
local Cooldown = false
local Duration = 25 -- Duration in Seconds.

game.Workspace.PowerBox.Button.ProximityPrompt.Enabled = false

local lightList = {}
for _, v in pairs(workspace.Map.KillArea.Lights:GetDescendants()) do
	if v:Isa("Model") and v.Name == "LightBulb" then
		table.insert(lightList,v)
	end
end

task.wait(25)
for _, v in pairs(lightList) do -- Pairing as an instance.
	--v.Bulb.PointLight.Brightness = 0 -- Making the "Lights" Brightness zero (Off).
	v.Bulb.PointLight.Enabled = false
	v.Light.Transparency = 1 -- Simply making it that the Neon Part is Transparent.
end

game.Workspace.BackgroundSound.Ambience:Stop() -- BackgroundSound Sound will (Stop) Playing.
game.Lighting.Atmosphere.Density = 1 -- Creating the Fog pressure level.
game.Lighting.Atmosphere.Haze = 10 -- Same Here.
game.Workspace.Monster.Torso.PointLight.Enabled = true -- Making the Monsters Torso has translucent PointLight when "PowerOutage" is active.
game.Workspace.PowerBox.Button.ProximityPrompt.Enabled = true
game.Workspace.PowerBox.Button.Color = Color3.new(0, 0, 0)
script.PowerOff:Play() -- PowerOff Sound will (Play).
script.PowerOn:Play() -- PowerOn Sound will (Play).

Prompt.Triggered:Connect(function()
	if Cooldown == false then
		Cooldown = true
		for _, v in pairs(lightList) do -- Pairing as an instance.
			--v.Bulb.PointLight.Brightness = 1 -- Making the "Lights" Brightness 1 (On).
			v.Bulb.PointLight.Enabled = true
			v.Light.Transparency = 0 -- Simply making it that the Neon Part is Transparent.
		end
		game.Workspace.BackgroundSound.Ambience:Play() -- BackgroundSound Sound will (Start).
		game.Lighting.Atmosphere.Density = 0 -- Disabling the Fog pressure level.
		game.Lighting.Atmosphere.Haze = 0 -- Same Here.
		game.Workspace.Monster.Torso.PointLight.Enabled = false -- Making the Monsters Torso has Non-translucent PointLight when "PowerOutage" is inactive.
		game.Workspace.PowerBox.Button.ProximityPrompt.Enabled = false
		game.Workspace.PowerBox.Button.Color = Color3.new(0, 161, 0)
		script.PowerOn:Play() -- PowerOn Sound will (Play).
		script.PowerOff:Stop() -- PowerOff Sound will (Stop).
		task.wait(Duration)
		Cooldown = false
	end
end)

quick problem the PowerOutage Event doesn’t loop.

But other then that everything else seems to work perfectly fine thank you.