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

How to find all children with filter?

Asked by
Scaii_0 145
5 years ago
Edited 5 years ago

So what I mean by this is how would I find all the children named 'THIS' in this model? And if it is called 'THIS' execute this function?

I know how to find all the children of a part but don't know anything past that...

local children = model
for i = 1, #children do

--if childs names is THIS then 
--rest of code

Of course, if there is a more efficient way that would be appreciated.

0
Well your comment is correct already aazkao 787 — 5y
0
Isn't there something like workspace _,v in pairs do? Could I use that method, and how would I? Scaii_0 145 — 5y
0
Also if I am using this method how would I interact with that specific child? Scaii_0 145 — 5y
0
the in pairs functions loops through all the children of the model, if you already got the table of the model's children already your code will work fine aazkao 787 — 5y
View all comments (2 more)
0
How would I set that child as a local? Scaii_0 145 — 5y
0
what does that mean User#19524 175 — 5y

1 answer

Log in to vote
1
Answered by
aazkao 787 Moderation Voter
5 years ago

Here I suppose you know how to get the children of the model already so i will just leave that for you to write, store it in the table i named "children"


for i =1,#children do wait() if children[i].Name == "this" then--your if statement print("this is found at index"..i)--this code will run if the part is named this, and shows you the index of the part in the table else print("this is not found at index"..i)--this code will run if the part is not named this, and shows you the index of the part in the table end end

Alternatively with the in pairs loop, both will work

for i,v in pairs(children) do

    if v.Name == "this" then
        print("this is found at index"..i)
    else 
        print("this is not found at index"..i)
    end
end
0
But what if there are multiple instances named 'this'? Scaii_0 145 — 5y
0
I wanted to find a specific 'this' which has a child called 'NEWTHIS'. Scaii_0 145 — 5y
0
If there are say, 2 parts named "this", and they are the first and third part of the model, then it will print it out two times and say this is found at index 1 and this is found at index 2 aazkao 787 — 5y
0
CORRECTION for my above comment, it will print out this is found at index 1 and this is found at index 3, if you want to make sure "this" has a child named "newthis" just add another if statement aazkao 787 — 5y
0
use the method FindFirstChild(), if you dont know what that is here is the wiki for it: https://www.robloxdev.com/api-reference/function/Instance/FindFirstChild aazkao 787 — 5y
Ad

Answer this question