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

How can i find multiple children of a child using FindFirstChild?

Asked by 7 years ago
Edited 7 years ago

So I know how to find ONE child of a parent like so

game.Workspace.Example:FindFirstChild("Child1")

But what if I need to find multiple children of a child?? would it be,

game.Workspace.Example:FindFirstChild("Child1").Child2:FindFirstChild("Child3")

?

This has been giving me a headache and the wiki is no help..

Please help asap..

0
FindFirstChild cannot be used to find multiple children. If you're trying to execute certain things for multiple objects, for loop with pairs ( http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions#pairs ) used with :GetChildren ( http://wiki.roblox.com/index.php?title=API:Class/Instance/GetChildren ) might help. GmDTheSine 70 — 7y
0
Thanks i'll definetely look into that! EtherealTrin 45 — 7y

1 answer

Log in to vote
0
Answered by
Aimarekin 345 Moderation Voter
7 years ago

You can not include 2 events in the same line. Here would be what you're looking for....

local findchild1 = nil
local findchild 2 = nil

local findchild1 = game.Workspace.Example:FindFirstChild ("Part1")
if findchild 1 ~= nil then
        local findchild 2 = findchild1:FindFirstChild ("Part2")
end

This way, you would findfirstchild of the first object, and if its not nil, find the second into the variable findchild2.

0
I didnt really understand some of that but it did help. EtherealTrin 45 — 7y
0
You can not findfirstchild of another firstfirdchild Aimarekin 345 — 7y
0
So what we do is setting findchild1 to the first find child Aimarekin 345 — 7y
0
Ugh im having typos on wrriting findfirstchild sorry xd Aimarekin 345 — 7y
View all comments (3 more)
0
And, if findchild1 is an object (Not nil) then we set findchild2 to the findchild you wanted to do after Aimarekin 345 — 7y
0
Sorry for not explaining my fault Aimarekin 345 — 7y
0
"FindFirstChild" is a function, not an event, and you *can* use it multiple times in a single line - but one shouldn't because (as you showed) one should always check to see if :FindFirstChild returned 'nil' or not first. @melissa: If you are certain that the object will be there, you don't need to use FindFirstChild at all, ex: print(game.Workspace.MyFolder.MyModel.MyPart) --is perfectly valid chess123mate 5873 — 7y
Ad

Answer this question