"TIP OF THE DAY Did you know FindFirstChild has a second, optional, parameter which will search through every descendant?" How would I use this? I look all over the wiki.
The "Tip of the day" Thing?
2 answers
Lets say that this is the hierarchy or an object you are trying to find:
Workspace
Model
Banana
Normally to find the object Banana you would have to create a recursive function to search workspace. When the second argument is true FindFirstChild will recursively search the directory until it finds the object.
Workspace:FindFirstChild("Banana",true) --Would return Banana
Workspace:FindFirstChild("Banana") --Would not find Banana
The equivalent recursive function.
function Recurse(Location,Name)
for _,n in pairs(Location:GetChildren()) do
if n.Name == Name then
return n
end
Recurse(n,Name)
end
end
Recurse(Workspace,"Banana")
The wiki says:
Instance FindFirstChild (
string name,
bool recursive = false
)
string name means the name of the child you want to find, this is the standard use.
bool recursive = false this is the optional parameter that the tip of the day is talking about, set this to true and it will search every child for more children with the name. Example:
Here's your explorer
workspace
Model
Part
and an example script:
part = game.workspace:findFirstChild("Part",true)
part.Name = "Found You!"
Here's your explorer after the script runs
workspace
Model
Found You!
This discussion is preserved as it was. New answers, comments, and votes are closed.
