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
9 years ago
while true do
game.Lighting.TimeOfDay = ("12:00:00")
game.Workspace:GetChildren("PointLight").Enabled = false
wait(5)
game.Lighting.TimeOfDay = ("01:00:00")
game.Workspace:GetChildren("PointLight").Enabled = true
wait(5)
end

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 9 years ago

You could use a simple recursive loop.

function toggleLights(state)
    local lights={}
    local function recurse(p)
        for i,v in next, p:GetChildren() do
            if #v:GetChildren() > 0 then
                recurse(v)
            end
            if v:IsA("PointLight") then
                v.Enabled=state
            end
        end
    end
    recurse(workspace)
end

while true do
    game.Lighting.TimeOfDay = ("12:00:00")
    toggleLights(false)
    wait(5)
    game.Lighting.TimeOfDay = ("01:00:00")
    toggleLights(true)
    wait(5)
end

(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 — 9y
Ad

Answer this question