I know it would be something along the lines of this:
game.Players.PlayerAdded:connect(function(plr) wait(5) for k, p in pairs(plr.Character:GetChildren()) do if p.ClassName=="Hat" then p:Destroy() end end end)
Removes all hats in Workspace.
Workspace.DescendantAdded:connect(function(obj) if obj:IsA("Hat") then wait() obj:Destroy() end end)