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

[UNSOLVED] How to turn lights on in 54 brick by doing a loop?

Asked by
traigla 75
9 years ago

I have 54 bricks in one model each with a spotlight in. I want to be able to toggle the lights on and off. But how would I be able to change the enabled value of every spotlight with just one loop function instead of renaming all the parts.

2 answers

Log in to vote
2
Answered by 9 years ago

Try this one it should work, it worked for me!

for i,v in pairs(script.Parent:GetChildren()) do
    for o,b in pairs(v:GetChildren()) do
        if b.ClassName == "PointLight" then
            if b.Enabled == false then
                b.Enabled = true
            end
        elseif b.ClassName == "SpotLight" then
            if b.Enabled == false then
                b.Enabled = true
            end
        end
    end
end

Hope this works for you, make sure the bricks are the script's parent's children!

Ad
Log in to vote
0
Answered by 9 years ago

This would be the easiest way.

Put this script in the model:

local parts = script.Parent:GetChildren();  -- Get All the parts in the model.

for i,v in ipairs(parts) do  -- Loops through the table.
    if v:FindFirstChild("SpotLight") then  -- Finds if the part has a item called "SpotLight".
        v.SpotLight.Enabled = true;  -- Enables the spotlight.
    end
end

Hope that helped. :)

0
Doesn't work. traigla 75 — 9y

Answer this question