What’s the difference between :GetChildren() and :GetDescendants()? I dont really understand, because I dont see any difference
One returns everything like recursively while other only 1st layer
Etc:
Hierarchy:
Part: {
Part: {}
Part: {Attachment}
}
GetChildren returns: {Part,Part}
GetDescendants returns: {Part,Part,Attachment}
Please try reading roblox documentation before making post on devforum
https://create.roblox.com/docs/reference/engine/classes/Instance#GetChildren
https://create.roblox.com/docs/reference/engine/classes/Instance#GetDescendants
hello. please. search the content that your want to archives on a seach engine before posting. What is the difference between GetChildren() and GetDescendants()?
GetChildren only gets the children of a instance, but :GetDecendants alos get the children of that child, and the children of that child, and so on
GetChildren Gets only the first layer of children, for example, the model is Model > Part > Decal, GetChildren(Model) will only get the part, as Decal is NOT a child of Model, however, GetDescendants gets ALL instances under it, meaning decal WILL be included.
workspace:GetChildren()
workspace:GetDescendants()
GetChildren returns the first layer of children, in no particular order. GetDescendants returns a list of every instance inside of another, again in no particular order. That includes the children’s children, and their children, and so on. Everything inside!
basically if you were a grandpa:
-
get children would return your kids
-
get descendants would return your grandkids aswell
(not to be taken weirdly)
ALSO PLEASE DO A QUICK CHATGPT PROMPT BEFORE YOU MAKE A POST oml bro…
ngl this is kinda hard to read
agreed however
getChildren() only gets the first row of children.
getDescendants() gets the children and the children of the children
Btw, The ‘Folder’ and ‘Child’ can also be descendants for future reader. Workspace:GetDescendants() returns all the objects in the workspace.
Great explanation, I will add though that there is actually a particular order to both methods, which is the order in which they were added to their parent instance. (source)
instance:GetDescendants() recursively calls :GetDescendants() on each of instance’s children, so the return order is harder to keep track of, but will always behave according to the order of parent assignment
It’s a little hard for me to explain in words so here’s a code sample to visualize it
local function getDescendants(parent : Instance) : {Instance}
local descendants = {}
for _, v in parent:GetChildren() do
table.insert(descendants, v)
for _, v in getDescendants(v) do
table.insert(descendants, v)
end
end
return descendants
end
Why is that… like the perfect way of explaining it, and your right bro, he should lve looked in documentation, or at least replied to his post ![]()
Not necessarily defending OP posting before looking in documentation but I will admit as someone pretty new to this the documentation is a lot and easy to get lost in. Thank you for those links.
Little bit of a tangent from the overall thread, but LUA’s syntax is really confusing to me.
Is there an easy, cheeky way to get a second child inline without calling ALL descendants and blowing everything up? Like, if I have folder “RigCalls” in workspace, and it’s full of rigs, I can loop through rigcalls with a for/do loop and GetChildren to get all of the rigs in that folder. But if I have 100 rigs, that’s… bad. And I want to organize. So say I had folders “First20” “Second20” etc inside RigCalls and each had a bunch of rigs. Is there an easy way to access the rig object in each subfolder without calling anything other than the top level rig object?
There’s FindFirstChildWhichIsA which sounds like it would loop down to find the first descendent that’s a given object type, but it also sounds like it’s a once only type of function.
Could I get away with workspace.RigCalls:GetChildren(workspace.RigCalls:GetChildren())?
Or is my only option actually going through and doing nested loops for everything?
GetChildren doesnt take any arguments
workspace.First20:GetChildren()?
GetChildrendoesnt take any arguments
Good to know. This may be a dumb question, but I’m really confused and I feel like all of my basic knowledge on function arguments (and everything else) is kind of out-the-window with LUA. How can I know from a documentation glance whether something takes arguments and what it takes?
![]()
Edit: It will tell me. In the parenthesis. Like it did directly below the function I screenshot. I… am dumb. ![]()
workspace.First20:GetChildren()?
workspace.RigCalls.First20.GetChildren() would work for sure I would just have to do more loops, which I’m uhh trying to avoid. I think realistically that’s the only simple, effective option, or just not worrying about sorting the rigs by folder. Will think on it ig. Thank you so much for your help!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.



