game.Workspace.ChildAdded:Connect(function(player)
	if player:FindFirstChild('Humanoid') then
		for i,v in pairs(player:GetChildren()) do
			if v:IsA("Accessory") then
				for i,e in pairs(v:GetChildren()) do
					if e.className == ("Attachment") then
						if e.Name ~= ("HairAttachment") then
							e.Parent:Destroy()
						elseif
							e.className == ("Attachment") then
								if e.Name == ("HairAttachment") then
								print('Hair Found')
							end
						end
					end
				end
			end
		end
	end
end)

For some reason, It shows no errors but it doesn't work.

Brief explanation of what I want the script to do:

I want to keep the hair but delete the hats.