getinstances

Returns the instances currently stored in the internal instance cache.

Syntax

getinstances() -> table

Returns

TypeDescription
tableArray 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)
end

Finding Specific Instances

-- Find cached Scripts
local scripts = {}
for _, inst in ipairs(getinstances()) do
    if inst:IsA("Script") then
        table.insert(scripts, inst)
    end
end

Notes

  • The result is a snapshot of the current cache
  • Nil-parented instances are included when they are cached
  • Later calls may contain additional entries