Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Two Part with two lights enabled true/false?

Asked by
korj5 0
10 years ago
1while true do
2game.Lighting.TimeOfDay = ("12:00:00")
3game.Workspace:GetChildren("PointLight").Enabled = false
4wait(5)
5game.Lighting.TimeOfDay = ("01:00:00")
6game.Workspace:GetChildren("PointLight").Enabled = true
7wait(5)
8end

Any parts that have PointLight shall be enabled at 01:00:00 not 12:00:00.

1 answer

Log in to vote
1
Answered by 10 years ago

You could use a simple recursive loop.

01function toggleLights(state)
02    local lights={}
03    local function recurse(p)
04        for i,v in next, p:GetChildren() do
05            if #v:GetChildren() > 0 then
06                recurse(v)
07            end
08            if v:IsA("PointLight") then
09                v.Enabled=state
10            end
11        end
12    end
13    recurse(workspace)
14end
15 
View all 23 lines...

(Tell me if this doesn't work, I just quickly wrote this up)

0
There's no need to check if it has at least 1 child--it works exactly the same for empty objects. That said, is there a good reason to use `next` instead of pairs? BlueTaslem 18071 — 10y
Ad

Answer this question