Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would I get all services and instances/objects in my game?

Asked by 10 years ago

I want to get all services and objects in my game, I thought about using GetChildren() over and over and over, but I realized that if someone else used this, they may have more models in workspace then I do, so then this method would not work, so how could I do this?

1 answer

Log in to vote
1
Answered by 10 years ago
local instanceTable = {}
function getInstances(Instance)
    Instance = Instance or Game
    for i,v in pairs(Instance:GetChildren()) do
        table.insert(instanceTable, v)
        getInstances(v)
    end
end

getInstances() --instanceTable is now filled with all in-game instances.

Ad

Answer this question