QueryDescendants return value contains duplicates

When a list of selectors is provided and an instance matches more than one of the selectors, it will be included in the returned array multiple times.

Repro steps:

  1. Open any place in Studio
  2. Run =workspace:QueryDescendants("Terrain,Terrain") in the command bar
  3. Observe that the array in the output window lists Terrain twice

First observed 21 Jan in Studio version v0.704.7041059. Observed in a live game on the same day.

Notes:

  • This also reproduces in live games
  • Not limited to identical selectors; these work too: "Terrain,#Terrain", "Terrain,>Terrain" etc

Expected behavior

The results should be deduplicated so that any one instance only ever appears one or zero times.

Yes, this is exactly how method is implemented to behave.

Thanks for the info. This is somewhat surprising from a usability standpoint - developers would need to do their own logic to deduplicate results in all non-trivial cases. Presumably deduplicating at the engine level is costly in a way that outweighs this? In any case, I can’t find this detail in the docs - can make a separate request for that.

The main reason is that for best performance it was important to store instances as soon as they are discovered.
Additionally the expression doesn’t have to be parsed in full before starting the search&filter.

This might be something we might rework to merge in the future, but it was a choice and not an oversight.
We were also looking to add is() function along the lines of has()/not() as it can be a more explicit way of saying “I want either match” and can be nested "is(Model, Part) > is(IntValue, NumberValue)"

I think it would be better to be able to explicitly group queries. This is, if i remember correctly at least, already somewhat possible by using something like ":not(:not(query, query2...))".
Example of what this might look like: "(Model, Part, #HelloWorld, .Center) > (IntValue, [Transparency = 1], :has(NumberValue))".
Unless i misunderstood and that is exactly what is() is supposed to do, in which case, my mistake.