Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is it possible to loop through two things at once?

What im trying to do is loop through workspace and serverstorage at the same time. So is it possible?

5 comments

0

what do u mean?

0

Im talking about a for loop. For example for i,v in pairs (game.Workspace, game.ServerStorage()) do. IF there is something like this.

0

for both im one loop

0

coroutines or nested loops to create a matrix web

0

how to delete another persons comment

1 answer

Yes this is possible. I would recommend using coroutines.

Example:

local firstLoop = coroutine.wrap(function()
	for _,v in pairs(game.Workspace:GetChildren()) do
		print(v.Name) 
	end
end)
firstLoop()

local secondLoop = coroutine.wrap(function()
	for _,v in pairs(game.ServerStorage:GetChildren()) do
		print(v.Name) 
	end
end)
secondLoop()

Coroutines basically allow code to run without having to yield the code after it.

Here's some more info if you need more help: https://developer.roblox.com/en-us/api-reference/lua-docs/coroutine

2 comments

0

No, it is not possible, coroutines are not new threads.

0

It is possible o3o, I tried it.

This discussion is preserved as it was. New answers, comments, and votes are closed.