I want to remove the accessories of all players that join and ran into a bit of an issue. This is my code (located in ServerScriptService), which iterates through the character instance. There are no errors but none of my accessories are not being removed. Here’s my code:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if char:FindFirstChild("Humanoid") then
for i, v in pairs(plr:GetChildren()) do
if v:IsA("Accessory") then
v:Destroy()
end
end
end
end)
end)
I understand that I can achieve the same goal with this code, but want to know what is wrong with my other code for the purpose of learning.
Alternative Solution
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAppearanceLoaded:Wait()
plr.Character.Humanoid:RemoveAccessories()
end)