I am making a “PowerOutage” System, and I am trying to make that the Script can finalizes all the Models associating in the “Lights” Folder. How would I do this?
Script:
-- PowerSystem Script
while true do
local randomnumber = wait(math.random(5, 7))
print(randomnumber)
game.Lighting.Atmosphere.Density = 1
game.Lighting.Atmosphere.Haze = 10
script.PowerOff:Play()
script.PowerOn:Play()
workspace.Lights.LightBulb.Bulb.PointLight.Brightness = 0 -- Here
workspace.Lights.LightBulb.Light.Transparency = 1 -- Here
local randomnumber = wait(math.random(9, 20))
print(randomnumber)
script.PowerOn:Play()
script.PowerOff:Stop()
workspace.Lights.LightBulb.Bulb.PointLight.Brightness = 1 -- Here
workspace.Lights.LightBulb.Light.Transparency = 0 -- Here
game.Lighting.Atmosphere.Density = 0
game.Lighting.Atmosphere.Haze = 0
end
3 Likes
Use for loops to automatically set the Lights to anything you want
the Workspace is displayed in this order
Workspace > Lights ← (Folder) > LightBulb ← (Model)
for i, v in pairs(workspace.Lights.Folder:GetDescendants()) do -- change folder name. You can use GetChildren(), idk how your folder is organised
if v:IsA("Model") and v.Name == "InsertModelName" then -- change model name
--code
end
end
Would the format look like this?
for i, v in pairs(workspace.Lights.Folder:GetDescendants()) do -- change folder name or use GetChildren(), idk how your folder is organised
if v:IsA("Model") and v.Name == "LightBulb" then -- change model name
--code
end
end
while true do
local randomnumber = wait(math.random(5, 7))
print(randomnumber)
---------------------------------------------------------------------------------
game.Lighting.Atmosphere.Density = 1
game.Lighting.Atmosphere.Haze = 10
script.PowerOff:Play()
script.PowerOn:Play()
local randomnumber = wait(math.random(9, 20))
print(randomnumber)
script.PowerOn:Play()
script.PowerOff:Stop()
workspace.Lights.LightBulb.Bulb.PointLight.Brightness = 1
workspace.Lights.LightBulb.Light.Transparency = 0
game.Lighting.Atmosphere.Density = 0
game.Lighting.Atmosphere.Haze = 0
end
No, since the index’s are in the for loop. Can you show the folder and how it is organised?
for i, v in pairs(workspace.Lights:GetDescendants()) do
if v:IsA("Model") and v.Name == "LightBulb" then
while true do
local randomnumber = wait(math.random(5, 7))
print(randomnumber)
---------------------------------------------------------------------------------
game.Lighting.Atmosphere.Density = 1
game.Lighting.Atmosphere.Haze = 10
script.PowerOff:Play()
script.PowerOn:Play()
local randomnumber = wait(math.random(9, 20))
print(randomnumber)
script.PowerOn:Play()
script.PowerOff:Stop()
v.Bulb.PointLight.Brightness = 1
v.Light.Transparency = 0
game.Lighting.Atmosphere.Density = 0
game.Lighting.Atmosphere.Haze = 0
end
end
end
oh yeah not to mention the
Blockquote ------------------------------------------------------------------------------------------------------- is where the Lighting Brightness and Transparency goes.
never mind what I said, sorry I was confused.
@yoshicoolTV uhhhh problem it only does the function once.

This is my Script:
-- PowerSystem Script
while true do
for i, v in pairs(workspace.Lights:GetDescendants()) do
if v:IsA("Model") and v.Name == "LightBulb" then
while true do
local randomnumber = wait(math.random(5, 7))
print(randomnumber)
v.Bulb.PointLight.Brightness = 0
v.Light.Transparency = 1
game.Lighting.Atmosphere.Density = 1
game.Lighting.Atmosphere.Haze = 10
script.PowerOff:Play()
script.PowerOn:Play()
local randomnumber = wait(math.random(9, 20))
print(randomnumber)
script.PowerOn:Play()
script.PowerOff:Stop()
v.Bulb.PointLight.Brightness = 1
v.Light.Transparency = 0
game.Lighting.Atmosphere.Density = 0
game.Lighting.Atmosphere.Haze = 0
end
end
end
end
just copy paste the script that i sent, the while loop is already in the for loop
yeah but the light won’t turn on and off tho
i think it might be because of your random wait
@yoshicoolTV that is not the case I just got rid of the random waits and no affect happened
I am honestly not sure why its not working
would you like the kit so you mess around with it?
yea i think that would be better