Search code examples
luaroblox

Check if something has children in ROBLOX Lua?


I need to check if something has children in ROBLOX Lua. I know of FindFirstChild(string) which finds the first child with a name matching string, and I have been using that to see if the instance has a certain child in it, but now I want to see if it has ANY at all. I was hoping for something like:

if Instance:GetChildren() then
  --Do something
end

How do I do something like that?


Solution

  • This method will get a table of the Instance's children and check if it is more than 0, meaning it has children.

    if #Instance:GetChildren() >0 then 
      --It has children!
    end