QueryDescendants partial string selectors/range selectors

As a Roblox developer, it is currently too hard to effectively utilize QueryDescendants in trees with names and values that are determined at runtime.

1. It would help if string property selectors, or at the very least the special Name selector, were able to take substring matches.

Take these pre-QueryDescendants examples:

for _, part in character:GetDescendants() do
    --Left Arm, Right Arm, LeftUpperArm, RightUpperArm, LeftLowerArm, RightLowerArm
    if part:IsA("BasePart") and part.Name:sub(-3) == "Arm" then

    --LeftUpperArm, RightUpperArm, LeftUpperLeg, RightUpperLeg, UpperTorso
    elseif part:IsA("BasePart") and part.Name:find("Upper") then

    --Left Arm, Left Leg, LeftUpperArm, LeftHand, ...
    elseif part:IsA("BasePart") and part.Name:sub(1, 4) == "Left" then

None of these can be mapped to a single name selector query. At best, one would have to write multiple selectors (, syntax) or pre-tag these parts with attributes or tags based on individual needs. Pre-tagging is often not a viable approach when it comes to dealing with existing places or toolbox models and when creating third party libraries.

It would help if there was special syntax to support substring Name selection, for example:

#..Arm --ends in "Arm"
#%Upper% --contains "Upper"
#^Left --starts with "Left"

These are just illustrative examples and may conflict with current syntax. (Side note: the Name selector # does not support quotes for names and an explicit [Name=""] property selector must be used when dealing with such names.)

2. There are cases where a discrete property values are not enough to define a query.

Another current age example:

local ignore = {}
for _, part in workspace.Map:GetDescendants() do
    if part:IsA("BasePart") and part.Transparency > 0.1 then
        table.insert(ignore, part)
    end
end
lineOfSightParams.FilterDescendantsInstances = ignore

This can not be mapped with QueryDescendants unless you already know exactly which transparencies are used in the map model. However, I do believe that the following use case is in line with the developer experience I expect from QueryDescendants:

lineOfSightParams.FilterDescendantsInstances =
    workspace.Map:QueryDescendants(`BasePart[Transparency>"0.1"]`)

There are obviously more opportunities with number ranges specifically, but just the addition of GT/LT would already cover most when used alongside :not.


If Roblox is able to address these issues, it would improve my development experience because it would cleanly eliminate certain long and nested children/descendants checks in loops.

7 Likes

you 100% cooked i hope a staff reads this

1 Like

Just tried using QueryDescendants and was pretty sad to find out I couldn’t use >= when checking attributes.

1 Like