Query
a reusable filter that matches entities by the components they hold
Fields
2 members
- count:
number number of entities currently matching the query criteria
- Entity:
QueryColumn column array of matched entity instances
Methods
3 members
- Refresh
(): number re-evaluate the query filter and answer the count of matching entities
- With
(name: string): Query answer a new query narrowed to require the specified component
Parameters
Name Type Description name string Component name required by the query filter. - Without
(name: string): Query answer a new query narrowed to exclude the specified component
Parameters
Name Type Description name string Component name excluded by the query filter.
Filtering and Iterating ECS Entities
Lifecycle: Server
A query keeps its matches in dense arrays that you refresh and then walk by index.
Luau
local query = game.World.Query("Tool")local count = query:Refresh()print("Matched tools count:", count)for i = 1, query.count do local entity = query.Entity[i] print(string.format("Slot %d entity: %s", i, tostring(entity)))end