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
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.
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
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!
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).
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)