getinstances
Returns the instances currently stored in the internal instance cache.
Syntax
getinstances() -> tableReturns
| Type | Description |
|---|---|
table | Array of cached instances |
Description
getinstances returns the Instance values currently present in the cache.
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 cached Scripts
local scripts = {}
for _, inst in ipairs(getinstances()) do
if inst:IsA("Script") then
table.insert(scripts, inst)
end
endNotes
- The result is a snapshot of the current cache
- Nil-parented instances are included when they are cached
- Later calls may contain additional entries
Related Functions
getnilinstances- Get only nil-parented instances