Make programming easier with Roblox's best Instance search module, rQuery!

Get the module here:


Intro


rQuery is a free, open-source module designed to provide a more advanced alternative to Roblox’s built-in search functions (:FindFirstChild, :WaitForChild, etc.). It extends search functions to add more parameters to search. Currently, the module allows for:

  • Searching instances for specified CollectionService tags
  • Searching instances for properties with a specified value
  • Defining a function to query (see rQuery:QueryFunction)

More features are planned! See the Roadmap below for more details.


Usage


Click me to read the API

Module

module.new(object: Instance)

Returns an rQuery object. The object parameter is what rQuery will use for all queries.

rQuery object

rQuery:QueryFirstChildWithTag(tag: string, queryDescendants: boolean)

Returns the first child having CollectionService tag tag. If queryDescendants is true, rQuery will search descendants returned by object:GetDescendants(). Otherwise, it will use instances returned by object:GetChildren().

rQuery:QueryChildrenWithTag(tag: string, queryDescendants: boolean)

Similar to QueryFirstChildWithTag, but returns a table of all instances with CollectionService tag tag, not just the first.

rQuery:QueryFirstAncestorWithTag(tag: string)

Returns the first ancestor with CollectionService tag tag, with “first” being defined as the latest ancestor (e.g. an eligible Parent would be returned even if game had the tag).

rQuery:QueryAncestorsWithTag(tag: string)

Returns all ancestors of the object with CollectionService tag tag.

rQuery:QueryFirstChildWithProperty(property: string, value: any, queryDescendants: boolean)

Returns the first descendant that has property property of value value. queryDescendants has the same function as every other use here.

rQuery:QueryChildrenWithProperty(property: string, value: any, queryDescendants: boolean)

Similar to QueryFirstChildWithProperty, but returns all eligible children, not just the first discovered.

rQuery:QueryFirstAncestorWithProperty(property: string, value: any)

Similar to QueryFirstChildWithProperty, but queries ancestors, not children.

rQuery:QueryAncestorsWithProperty(property: string, value: any)

Similar to QueryFirstAncestorWithProperty, but returns all eligible ancestors.

rQuery:Rebind(newBind: Instance)

Changes the Instance the rQuery object uses for all queries.

rQuery:QueryFunction(direction: string, returnAll: boolean, filter)

An all-encompassing function that can be used for all queries.

direction has 3 valid values:

  • “Children” searches the Instance’s immediate children.
  • “Descendants” searches the Instance’s descendants.
  • “Ancestors” searches the Instance’s ancestry.

When true, returnAll will return all eligible objects. Otherwise, it will return only the first.

filter is a function that will return a boolean value when called as such:

filter(instance)

Roadmap


Features currently planned for rQuery:
  • An all-encompassing Query function that accepts a dictionary of parameters

Thanks for reading, and I look forward to the DevForum community's feedback!
10 Likes

Cool module. Thanks for the contribution.

1 Like

We’re halfway through the week, and I need ideas to work on for the next update! Select one type of update you want me to focus on below.

I should focus on:
  • Adding a Query method
  • Adding more options for selection (reply what they should be)
  • Misc. (reply what you want)

0 voters

UPDATE


rQuery version 0.2 released! This version adds a function rQuery:QueryFunction; see API above for details.

1 Like

You should change the function’s name to rQuery:Query() so it’s more efficient.

1 Like

Been a while since the last update, and I’m wondering where you want this module to go. Possible directions on the table include:

  • A parameter-based query.
  • Re-implementation of :GetDescendants which would return descendants in hierarchical order
  • Uh… I’m not sure what else.

Whichever of those two get more support, I’ll try to implement.

What should be the next update?
  • Param-based query
  • GetDescendants re-implementation

0 voters


Unfortunately, that won’t fit with future plans. I intend for a possible param-based query to be called rQuery:QueryParams, following a standard naming scheme. Thanks for the suggestions though!