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.
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!
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. :)