I have many lamps inside this building, and I want a button to be able to change all of them. However, each one is the child of a part, which is the child of a model, in a model filled with many models. How can I change the properties of all of these at once? I have tried using game.workspace.lights.light.point.SpotLight
but nothing happens.
You could use GetDescendants on the lights model and loop through the table and do something like if v:IsA(“PointLight”) then change the color
You could use the :GetDescendants to find any spotlights.
Do you have any examples? 30303030
local lights = game.Workspace.lights:GetDescendants()
for i, v in pairs (lights) do
if v:IsA("PointLight") then
-- Code
end
end
edit: sorry for not indenting idk how to do it here and im not in studio rn
Here’s a clip from my meltdown script. You can see the descendants in there.
local descendants = game.Workspace:GetDescendants()
script.Alarm:Play()
wait(5)
script.Failure:Play()
wait(15)
script.Test1:Play()
wait(5)
workspace.Glass1.Material = "Plastic"
workspace.Glass1.Transparency = 0
workspace["Reactor Core"].d.dd.Enabled = true
workspace.Floor10.PointLight.Color = Color3.fromRGB(198,0,0)
-- Loop through all of the descendants of the Workspace. If a
-- BasePart is found, the code changes that parts color to green
for index, descendant in pairs(descendants) do
if descendant:IsA("SurfaceLight") then
descendant.Color = Color3.fromRGB(190, 1, 1)
end
end
I would also recommends checking out this link:
in the code part, how should I format the color property change?
v.Color = Color3.fromRGB()
Something like this:
descendant.Color = Color3.fromRGB(0, 0, 0)
Replace the 0s with the numbers, and that should work, if it is referencing the light parts.
I remember wondering this exact same thing a few weeks ago.
Also replace my code that says “PointLight” to the light u got
Descendant has a red mark under it for some reason
Never mind, it was defined as v instead.
That means you have not defined descendant
. If you copied KingJoseon’s code, it should be v.Color