I'm trying to delete the player hats when the player spawns. Everything seems fine in the code, but it's not deleting my hats.
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) for _, child in ipairs(character:GetChildren()) do if child.ClassName == "Accessory" then child:Destroy() end end end) end)
*Updated to child:Destoy() but it still does not work
You have it right... But, because the hair is added after the fact you must wait for it to be added. Do this...
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) wait(0.5) for _,v in ipairs(character:GetChildren()) do print(v.Name) if v.ClassName == "Accessory" then v:Destroy() end end end) end)
just do
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character.Humanoid:RemoveAccessories() end) end)
honestly idk if this is gonna work. I saw the removeaccessories function a while ago and i just never got around to actually trying it.