RemoveAccessories function not working

The following is a server-side script located in ServerScript Service:

local Players = game:GetService("Players")

function onPlayerSpawned(player)
	player.CharacterAdded:connect(function(char)
		local humanoid = char:WaitForChild("Humanoid")
		humanoid:RemoveAccessories()
	end)
	end
game.Players.PlayerAdded:connect(function(player)
	onPlayerSpawned(player)
end)

The goal here is to remove all accessories (hats + hair) from the player - that way they aren’t over-riding our accessories we give them in-game.

Thanks ahead of time to any programming guru that helps out.

2 Likes

You don’t need a script for this you can change body parts, scale, etc at game settings

Game Settings => Avatar | Scroll Down
Screen Shot 2021-02-03 at 2.02.12 AM

1 Like

That is for clothing - that does not include accessories.

1 Like

You can do,

for _,child in pairs (humanoid.Parent:GetChildren()) do
				if child:IsA("Accoutrement") then
					child:Destroy()
				end
			end

Or

local RunService = game:GetService("RunService")
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		RunService.Stepped:wait()
		for i,v in pairs (char:GetChildren()) do
			if v:IsA("Accessory") then
				v:Destroy()
			end
		end
	end)
end)
2 Likes

Try changing CharacterAdded to CharacterAppearanceLoaded. I think the script is trying to remove your accessories before they load in.

2 Likes

Upon noticing further I believe it was that my script used:

player.CharacterAdded:connect(function(char)

rather then

player.CharacterAppearanceLoaded:Connect(function(character)

as it’s working now - and I haven’t tried your script yet. However I’ve heard that the removeaccessories() function can be faulty, so I will keep your code in mind.

Much appreciated, sorry for essentially the waste of time. I am trying to break my habit of frustrating myself rather then asking for help. It appears I only had to frustrate myself for a couple more minutes.

Well - that was perfect timing for that response haha.

2 Likes