game.Players.PlayerAdded:connect(function(p)
local c = p.Character
for i, chara in pairs(c:GetChildren()) do
if chara:IsA("Hat") then
chara:Destroy()
end
end
end)
I have this script that gets the players character and gets rid of their hats when they join the game. It works up to line 3, when it says that C is nil. Why is that? I'm not 100% sure that p.Character is how you get the character from the player, but that's what it says everywhere I went for help.
Someone help me with this?

3 comments
Thanks for the answer, it gets me a bit farther but for some reason the hats don't get removed. Any reason why?
Wait, never mind. I just realized I need to give the hats time to load before they are removed. Thanks for the help!
Anytime