Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function BasePartIterator(Table)
- local Length = #Table;
- local Thread = coroutine.create(function(_, Index)
- if (not Index) then --// If we're not passed an Index, make it 1;
- Index = 1;
- else
- Index = Index + 1; --// Otherwise increase it
- end
- for i = Index, Length do --// From the current Index to the Length
- if (Table[i]:IsA("BasePart")) then
- coroutine.yield(Table[i], i); --// These will be passed back again next iteration
- end
- end
- --// If none is found then it'll return nil, nil stops the for loop iterating
- end
- return function() --// Iterator
- local Success, BasePart, Index = coroutine.resume(Thread)
- return BasePart, Index;
- end
- end
- local WorkspaceDescendants = workspace:GetDescendants();
- for BasePart, IndexFound in BasePartIterator(WorkspaceDescendants) do
- print(BasePart:IsA("BasePart")); --// Always true
- print(WorkspaceDescendants[i] == BasePart); --// Also always true
- end
Advertisement
Add Comment
Please, Sign In to add comment