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

How do I get all instances of certain class?

Asked by 6 years ago

I am trying to get all the PointLights in a model. They are embedded in model in a model in a model, etc.

Here is my current code. I want lights array to be all the PointLights. named PointLight.

local lights = {}
local children = house:GetChildren()
for i = 1, #children do
    if children[i].Name == "PointLight" then
        lights.append(children[i])
    end
end

On a side note is .append() a real thing in LUA? (I have not tested it because I cannot get there)

children is contains just the direct descendants of house

2 answers

Log in to vote
-1
Answered by
GingeyLol 338 Moderation Voter
6 years ago
Edited 6 years ago
local thing = game.Workspace --place to be searched
for i,things in pairs(thing:GetDescendants()) do -- or :GetChildren()
if things:IsA("PointLight") then
things:Destroy() -- JUST A CODE
end
end
Ad
Log in to vote
-1
Answered by 6 years ago

Just loop through the children in the model and check if they inherit the "PointLight" class, like so.

local lights = {}

for i, child in pairs(house:GetChildren()) do
    if child:IsA("PointLight") then
        table.insert(light, child) -- insert `child` into the table `light`.
    end
end

0
-1 for ineffiency cabbler 1942 — 6y
0
@cabbler do you have a more efficient solution? crazywireman 2 — 6y

Answer this question