This is part of a script I'm making, it it SUPPOSED to turn lights off when the power goes off. Here is the script:
local p = game.Workspace.Lighting:GetChildren() for i = 1,#p do p.PointLight.Enabled = false end
However, this doesn't work. Help?
First, make sure that every instance in workspace.Lighting contains a PointLight. If your script encounters one that does not, it will fail. Also, you may want it to be a recursive function in case the light isn't located directly inside the object in Lighting.
This code will loop through every instance in workspace.Lighting and turn off any PointLights:
function LightsOff(Instance) for i,v in pairs(Instance:GetChildren()) do if v:IsA("PointLight") then v.Enabled=false end LightsOff(v) end end LightsOff(workspace.Lighting)