Error removing hats

Hello, I am making a game where the hats must be removed and I’m trying to make a script to do so. I am having trouble getting the hats to be removed, it doesn’t give me an error so I am not sure what I am doing wrong.

Here is the script:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		while wait() do
			local character = char:GetChildren()
		if character.className == "Accessory" then 
			character:remove() 
			end	
		end
	end)
end)

There’s a built-in method for removing all Accessories, Humanoid:RemoveAccessories().

The reason the code provided in the OP doesn’t work is because the Character variable was made equal to a table and the following line is checking if its ClassName is an Accessory. A loop would have needed to be utilized in this case to check the ClassName of every individual item.

1 Like