✓ Accepted answer
You have to first wait until the character loads its appearance before you remove anything. These may help: Player:HasAppearanceLoaded() , Player:ClearCharacterAppearance() , Player.CharacterAppearanceLoaded .
If you want to remove all accessories, that's easy. If you want to remove only literal "hats" then you should destroy Hat objects, as well as accessories which have a "HatAttachment". Here is what I would do:
player.CharacterAppearanceLoaded:connect(function(char)
for _,v in pairs(char:GetChildren()) do
if v:IsA('Hat') or (v:IsA('Accessory') and v:WaitForChild('Handle'):FindFirstChild('HatAttachment')) then
v:Destroy()
end
end
end)
However I notice that this event can be inaccurate, so here is a possibly safer option. They both use the same check though.
character.ChildAdded:connect(function(v)
if v:IsA('Hat') or (v:IsA('Accessory') and v:WaitForChild('Handle'):FindFirstChild('HatAttachment')) then
wait()
v:Destroy()
end
end)
2 comments
I tested it by changing remove to destroy, still didn't work.
Is this script inside of the character?