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

Find Model Based on Children?

Asked by
H26O 44
6 years ago
Edited 6 years ago

So I'm working on a script that can search models in the workspace however, I want to know if it is possible to find a model based on its children rather than its name.

Example:

I have two models named Model_A but one of them has a Part named Part1 and the other has Part2, How do I tell a script to find Part1 only or Part2 only and ignore the other.

(Also I'm keeping this all in one central script, so I don't want a script that is inside the Part and finds the parent)

https://gyazo.com/7e4e0472bfd894b9cc0045b618dcc650

1 answer

Log in to vote
1
Answered by
HaveASip 494 Moderation Voter
6 years ago
Edited 6 years ago

You should use GetDescendants. This function gets everything (not children). So if you want to check every object in the service ,model or folder use GetDescendants

Here is example:

for index ,object in pairs(workspace:GetDescendants()) do
    if object:IsA("Part") then
        if object.Name == "Part1" or "Part2" then
            print(object.Name)
        end
    end
end
Ad

Answer this question