How can I get all models in game?

So Basically, I want to make it so that a specific light part goes off at the same time. I have multiple of these models. About 12 to be exact. All the models are named the same. So how do I make it so all the lights turn off at the same time?

Here is the Script:

game.Workspace.Lights.CeilingLight.LightPart.SpotLight.Brightness = 0.5
	wait(0.1)
	game.Workspace.Lights.CeilingLight.LightPart.SpotLight.Brightness = 0.2
	wait(0.1)
	game.Workspace.Lights.CeilingLight.LightPart.SpotLight.Enabled = 0.2

How could I run it properly?

1 Like

I think this is what you’re trying to do:

for i, child in pairs(workspace:GetChildren()) do
    if child:IsA("Model") and child.Name == "Lights" then
        --Configure Properties Here
    end
end
1 Like
for i,v in pairs(workspace.Lights:GetChildren()) do
	v.LightPart.SpotLight.Brightness = 0.5
	--etc etc etc
end

(this assumes all children of workspace.Lights have the same naming as your code (Lightpart.SpotLight)
:+1:
To add onto this if you want all lights to turn off at the same time you might want to put

--start of the loop here
spawn(function()
	--code that turns the lights off here
end)
--end it here

and .Enabled can only be true or false not 0.2 but I assume that was a typo

4 Likes

It works like a charm. Thanks man.

1 Like