How can I loop through every thing in the workspace and then find all the items named loot?

How can I loop through every thing in the workspace and then find all the items named loot?

for _, item in workspace:GetDescendants() do
    if item.Name == "loot" then
        -- Here do your thing
    end
end
1 Like

The could be slow with a lot of things in your workspace, you should instead make a folder and store all loot instances inside that folder so you don’t have to iterate through everything.

3 Likes
for _, Loot in pairs(game.Workspace:GetChildren()) do
	if Loot.Name == "Loot" then
		-- Something you want to do
	end
end

This is one way of doing it.

The problem with this is you used GetChildren instead of GetDescendants so it won’t get everything in the workspace (like things in a model)

Ah, didn’t think of that. @MasonX890 you might want to use the suggestion that @domboss37 provided.

I would recommend using this method, it’s faster.