Page URLs:
Remove Accessories After Loading sample throws an error in line 6 - GetAccessories()
is a method of humanoid, not character model.
Lines 14 and 15 are not really necessary. New Player and Character Destroy Behavior is about to become enabled by default and is announced to become permanent behaviour around June this year. Even when disabled, disconnecting alone is not enough for the Player object to be released from memory as the comments say. The majority of other code samples don’t disconnect events like CharacterAdded and CharacterRemoving either. (With workspace.PlayerCharacterDestroyBehavior
disabled, manually destroying player and character instances is much more effective as well.)
New:
local Players = game:GetService("Players")
local function onPlayerAdded(player)
player.CharacterAppearanceLoaded:Connect(function(character)
-- All accessories have loaded at this point
local humanoid = character.Humanoid
local numAccessories = #humanoid:GetAccessories()
print(`Destroying {numAccessories} accessories for {player.Name}`)
humanoid:RemoveAccessories()
end)
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerAdded, player)
end
Players.PlayerAdded:Connect(onPlayerAdded)