I was wondering if anyone could fill me in. How would I get the children of the character. But only destroy Hats. I know how to get the name of something through :GetChildren() But how do I get the Hat object?
All Instances have a ClassName
property which is equal to what the instnace is. No matter what you rename an object its ClassName will always be the same. A Part is always a Part, even if you were to rename it "BoolValue". It is a Part, it always will be a Part, and it's ClassName will always be "Part."
Using this, we can check if a player has a Hat.
for i,v in pairs(character:GetChildren()) do --Make sure character is defined somewhere. if v.ClassName == "Hat" then --code end end
EDIT:
i is the index, and v is the value. This is most easily seen if you print them. For example, run this code:
for i,v in pairs(workspace:GetChildren()) do print(i.."is the current index!") print(v.."is the current value!") end
This for loop loops through all the children of workspace. For example, let's say you have three parts in workspace. The first time the loop iterates, v equals the first part. Then the second time the loop iterates, v equals the second part, and so on. i is a number, like 1, 2, 3. If i equals 2, then you know that the loop already iterated one time, and is working on its second.
But really, you'll understand the best if you try the code above with the prints.