superICH3
|
  |
| Joined: 25 May 2010 |
| Total Posts: 4729 |
|
|
| 06 Sep 2016 09:45 PM |
I want to find all models in workspace that have the name "Tree". I am having trouble accomplishing this. If I do :FindFirstChild("Tree") it only detects the first model named tree.
If someone could guide me, that would be great.
|
|
|
| Report Abuse |
|
|
superICH3
|
  |
| Joined: 25 May 2010 |
| Total Posts: 4729 |
|
| |
|
instawin
|
  |
| Joined: 04 Jun 2013 |
| Total Posts: 8777 |
|
|
| 06 Sep 2016 10:05 PM |
1. create a table to put all of the found tree models into 2. use a for loop to iterate through the children of workspace 3. add each tree to the list
local function getTrees() local trees = {}
for index, child in pairs(workspace:GetChildren()) do if child.Name == "Tree" and child.ClassName == "Model" then table.insert(trees, child) end end
return trees end
local trees = getTrees() print(#trees)
|
|
|
| Report Abuse |
|
|
superICH3
|
  |
| Joined: 25 May 2010 |
| Total Posts: 4729 |
|
| |
|
|
| 07 Sep 2016 03:57 PM |
Or use a while loop as long as:
Workspace:FindFirstChild("Tree",true)
Rename the tree and add to a table then Repeat... The true parameter tells the method to find trees that are also models of anything under the workspace node.
Afterwards you can choose to change all the trees names back or whatever.. |
|
|
| Report Abuse |
|
|