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...
1 | local children = model |
2 | for 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.
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"
1 | for 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 |
8 | end |
Alternatively with the in pairs loop, both will work
1 | for 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 |
8 | end |