Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

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

Asked by
bobder2 135
10 years ago

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?

Locked by OniiCh_n, M39a9am3R, and Shawnyg

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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.

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 :) bobder2 135 — 10y
Ad