Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[Answered]How to make GetChildren() get hats?

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?

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.

1 comment

0

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 :)

This discussion is preserved as it was. New answers, comments, and votes are closed.