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?
Your code isn't working because hats don't get added with the character, there is sometimes some delay between the character model being added and the hats being added to that mode. This code will avoid that delay:
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character.ChildAdded:connect(function(child) if child:IsA("Hat") then wait() child:Destroy() end end) end) end)