select $
it doesn't make sense. $ in MaxScript means "current selection". It can be a single node or a collection of nodes.
... or it can undefined. So, there is no point in making a selection in any of these three cases.
Another question is how to get only the root objects from a given collection of nodes.
In this example, we will use $ in the sense of "multiple selection" when we want to leave only the roots of the collection selected:
fn filterRoots nodes =
(
for node in nodes where node.parent == undefined or (finditem nodes node.parent == 0) collect node
)
select (filterRoots ($ as array))