getinstances
Returns all instances in the game.
Syntax
getinstances() -> tableReturns
| Type | Description |
|---|---|
table | Array of all instances |
Description
getinstances returns a table containing every instance currently in the game, including those not in the DataModel hierarchy.
Example
local instances = getinstances()
print("Total instances:", #instances)
-- Count by class
local counts = {}
for _, inst in ipairs(instances) do
local class = inst.ClassName
counts[class] = (counts[class] or 0) + 1
end
for class, count in pairs(counts) do
print(class, count)
endFinding Specific Instances
-- Find all Scripts
local scripts = {}
for _, inst in ipairs(getinstances()) do
if inst:IsA("Script") then
table.insert(scripts, inst)
end
endNotes
- Returns a very large table
- Includes nil-parented instances
- May impact performance if called frequently
Related Functions
getnilinstances- Get only nil-parented instances