Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

1 comment

0

Doesn't work.

This discussion is preserved as it was. New answers, comments, and votes are closed.