This script is supposed to remove all hats from a player when a player joins:
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
local d = character:GetChildren()
for i = 1, #d do
if d[i].ClassName == "Hat" then
d[i]:Destroy()
end
end
end)
end)
It doesn't work, though. Any help?

2 comments
This is kinda a request, figure out where the error is next time and then we can fix that error.
This question is fine, the code is both simple and short. If it was like 100 lines then you'd be totally right, though.