Can you find the children of a table?

Hello!

I was wondering if it was possible to find a child of a table, kind of how you’re able to do it with objects in workspace. If so, how would I go about it? I would use for loops but it’s kind of messy, but if there isn’t any other way, I’ll resort to it.

Thanks!

1 Like

You can use table.find

1 Like

Does it still work with subtables?

I think so.30 charssssss

1 Like

you can’t exactly find a ‘child’ of a table, though I think what you’re trying to do is get a certain index in a table.

Do this:


  local Details = {Number = 10; Cash = 20; Gold = 2;  }
  print(Details.Number) --->10

-- or with string indexes

  local Details = 

  {
   ["Cash"] = 130;
   ["Money"] = 2;
  }

  print(Details["Money"]) --> prints 2

using table.find to index something in a table is not the best way to do it, you can simply use dot syntax or the [ ] operator

2 Likes

Thanks! I’ll be sure to try it.

The issue with this is that I would have to go through each one. I’m pretty sure table.find should work in this case, however. Thanks though!

No you would not, I’m not sure I understand what you’re trying to do but table.find just returns the numerical index or occurence of an element in a table, you cannot use it to index an element unless through otherwise unnecessarily extra code.

For instance:

  local tab = {"a", "b"}  
  print(table.find(tab, "b")) --> would print 2

If you meant you wanted to get all children of an instance and create a table, use Instance:GetChildren()

Can you give an example or demonstration of what you’re trying to achieve??

Edit: @Winky_y Look at this post and the api

1 Like

I’m trying to use :GetCharacterAppearanceInfoAsync() which returns a ton of tables and subtables, and I’m trying to go through each one and trying to find the accessory ID, therefore I believe table.find with a for loop would be more efficient in this case.

Here’s the article:

table.find can’t be used to search for a value between tables within other tables, if you want to verify an element is within one table then you could do:

   if tab["a"]
-- or
   if table.find(tab, "a")

I’m just trying to find if the index is “id” or not.

I don’t think it would be that hard as table.assets.id.Value should work actually, and then just do a for loop which removes each ID one by one until all of them are gone.

How does table.find work? insert more characters here

This is helpful. Thank you! :smiley: