@SelDraken Would it be easier if I would to give you the Kit?
For it to loop the power outtage event, you just need to put a loop around the whole event.
Let me make a few adjustmentsâŚ
-- PowerOutage Script
local Lighting = game:GetService("Lighting")
local Part = script.Parent
local OnSound = Part:WaitForChild("PowerOn")
local OffSound = Part:WaitForChild("PowerOff")
local PowerBox = workspace.PowerBox
local Prompt = Part:WaitForChild("ProximityPrompt")
local Cooldown = false
local Duration = 25 -- Duration in Seconds.
local PowerState = "On"
--get list of lights
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
-- Helper functions
function SetPowerOn()
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
workspace.BackgroundSound.Ambience:Play() -- BackgroundSound Sound will (Start).
Lighting.Atmosphere.Density = 0 -- Disabling the Fog pressure level.
Lighting.Atmosphere.Haze = 0 -- Same Here.
workspace.Monster.Torso.PointLight.Enabled = false -- Making the Monsters Torso has Non-translucent PointLight when "PowerOutage" is inactive.
PowerBox.Button.ProximityPrompt.Enabled = false
PowerBox.Button.Color = Color3.new(0, 161, 0)
OnSound:Play() -- PowerOn Sound will (Play).
OffSound:Stop() -- PowerOff Sound will (Stop).
PowerState = "On"
end
function SetPowerOut()
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
workspace.BackgroundSound.Ambience:Stop() -- BackgroundSound Sound will (Stop) Playing.
Lighting.Atmosphere.Density = 1 -- Creating the Fog pressure level.
Lighting.Atmosphere.Haze = 10 -- Same Here.
workspace.Monster.Torso.PointLight.Enabled = true -- Making the Monsters Torso has translucent PointLight when "PowerOutage" is active.
PowerBox.Button.ProximityPrompt.Enabled = true
PowerBox.Button.Color = Color3.new(0, 0, 0)
OffSound:Play() -- PowerOff Sound will (Play).
OnSound:Stop() -- PowerOn Sound will (Play).
PowerState = "Off"
end
Prompt.Triggered:Connect(function()
SetPowerOn()
end)
SetPowerOn()
while true do
task.wait(Duration)
SetPowerOut()
while (PowerState == "Off") do
task.wait()
end
end
I get this in the Console â 00:42:15.503 Infinite yield possible on 'Workspace.PowerBox.Button:WaitForChild("PowerOn")' - Studio
In which script? I donât have that line in the script I posted to you.
âWorkspace.PowerBox.Button:WaitForChild(âPowerOnâ)â
It means it can not find what it is waiting for.
It is looking for a child of Workspace.PowerBox.Button, that is called âPowerOnâ and it canât find âPowerOnâ, under Workspace.PowerBox.Button
Am I spose to add BoolValues in the Button or something?
I think you might be just a little bit over your experience level with all of this.
What I suggest, is (because you mentioned you are using a kit) is to maybe take a break from this project, and spend a bit of time in studio experimenting with some more simple code, to get a good feel of how things are working.
Probably not the answer you want to hear, but sometimes (and I have been coding since the 80âs) when I start to get overwhelmed with some code or a new concept, I stop and experiment (play) with smaller pieces of code to understand each part of what I am wanting to achieve.
I would suggest playing with some proximity prompts, try making a switch that you can turn a single light on or off. Try to have a switch that you turn on, and once its on, it turns itself off after so many seconds and you can turn it on again.
Sorry I canât help more, but I donât work with kits or anything, thats too much trying to understand and fix someone elses code. We all sort of have a unique style to coding.
I am not using a Kit I meant do you want me to give it to you in a Kit?
And from what you are saying I am doing all of that.
I did fix the problem, so thanks.
Usually it is better to refactor the code before fixing it because refactoring (or tidying) will greatly help in fixing bugs, or you will find them while refactoring. And if you really change up the code, then you might not even encounter the same bug anymore
@Tomi1231 this is currently the code | The only problem I am facing is that Sound (On) plays when Player joins.
local Lighting = game:GetService("Lighting")
local Part = script
local Part1 = script.Parent
local OnSound = Part:WaitForChild("PowerOn")
local OffSound = Part:WaitForChild("PowerOff")
local PowerBox = workspace.PowerBox
local Prompt = Part1:WaitForChild("ProximityPrompt")
local Cooldown = false
local Duration = 23 -- Duration in Seconds.
local PowerState = "On"
-- Getting the List of Lights
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
-- Helper functions
function SetPowerOn()
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
workspace.BackgroundSound.Ambience:Play() -- BackgroundSound Sound will (Start).
Lighting.Atmosphere.Density = 0 -- Disabling the Fog pressure level.
Lighting.Atmosphere.Haze = 0 -- Same Here.
workspace.Monster.Torso.PointLight.Enabled = false -- Making the Monsters Torso has Non-translucent PointLight when "PowerOutage" is inactive.
workspace.PowerBox.Highlight.Enabled = false
PowerBox.Button.ProximityPrompt.Enabled = false
PowerBox.Button.Color = Color3.new(0, 161, 0)
OnSound:Play() -- PowerOn Sound will (Play).
OffSound:Stop() -- PowerOff Sound will (Stop).
PowerState = "On"
end
function SetPowerOut()
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
workspace.BackgroundSound.Ambience:Stop() -- BackgroundSound Sound will (Stop) Playing.
Lighting.Atmosphere.Density = 1 -- Creating the Fog pressure level.
Lighting.Atmosphere.Haze = 10 -- Same Here.
workspace.Monster.Torso.PointLight.Enabled = true -- Making the Monsters Torso has translucent PointLight when "PowerOutage" is active.
workspace.PowerBox.Highlight.Enabled = true
PowerBox.Button.ProximityPrompt.Enabled = true
PowerBox.Button.Color = Color3.new(0, 0, 0)
OffSound:Play() -- PowerOff Sound will (Play).
OnSound:Stop() -- PowerOn Sound will (Play).
PowerState = "Off"
end
Prompt.Triggered:Connect(function()
SetPowerOn()
end)
SetPowerOn()
while true do
task.wait(Duration)
SetPowerOut()
while (PowerState == "Off") do
task.wait()
end
end
Take the part where it plays the sound, and put it outside of the function, so that you can call the function to set up the lighting but not affect the sound.
Let me try to make an exampleâŚ
Here is a place file
PowerOutTest.rbxl (63.0 KB)
This example place has a simple setup to show how the flow of it all goes
The sounds are played outside of the funciton
Prompt.Triggered:Connect(function()
OnSound:Play()
OffSound:Stop()
SetPowerOn()
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.