I'm using GetChildren() on a character in an attempt to find their hats, but GetChildren() doesn't seem to include hats. Any workaround for this?
✓ ANSWER ACCEPTED
[Answered]How to make GetChildren() get hats?
1 answer
✓ Accepted answer
The Character does contain hats. Note that the hats are Hat or Accoutrement objects, which include the "Handle" Part only as a child.
Something like this will do the trick:
function getHats( character )
local children = character:GetChildren();
local hats = {};
for _, child in pairs(children) do
if child:IsA("Accoutrement") then
table.insert( hats, child );
end
end
return hats;
end
The part with the mesh will be called Handle inside.
It's possible that the Character will not be fully loaded when you initially search for hats. It might be a good idea to wait a moment to be sure. Off the top of my head I cannot think of any signal to indicate that the Character is finished loading but perhaps someone else can remember one.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
This is almost the exact code I have, and you were right, I needed to add a small wait() before getting children in order for it to add the hats to the table. Thanks for your help :)