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
6 years ago
Edited 6 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...

1local children = model
2for i = 1, #children do
3 
4--if childs names is THIS then
5--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 — 6y
0
Isn't there something like workspace _,v in pairs do? Could I use that method, and how would I? Scaii_0 145 — 6y
0
Also if I am using this method how would I interact with that specific child? Scaii_0 145 — 6y
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 — 6y
View all comments (2 more)
0
How would I set that child as a local? Scaii_0 145 — 6y
0
what does that mean User#19524 175 — 6y

1 answer

Log in to vote
1
Answered by
aazkao 787 Moderation Voter
6 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"

1for i =1,#children do
2    wait()
3    if children[i].Name == "this" then--your if statement
4        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
5    else
6        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
7    end
8end

Alternatively with the in pairs loop, both will work

1for i,v in pairs(children) do
2 
3    if v.Name == "this" then
4        print("this is found at index"..i)
5    else
6        print("this is not found at index"..i)
7    end
8end
0
But what if there are multiple instances named 'this'? Scaii_0 145 — 6y
0
I wanted to find a specific 'this' which has a child called 'NEWTHIS'. Scaii_0 145 — 6y
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 — 6y
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 — 6y
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 — 6y
Ad

Answer this question