Do for i,v loops yield a script?

Do for i,v loops yield a script if there is a wait at the end? for example

			for i,v in pairs(game.Teams.Home:GetPlayers()) do
					wait(7)
				end
			end
			for i,v in pairs(game.Teams.Away:GetPlayers()) do
					wait(7)
				end
			end

Would the loops run at the same time or would the second loop wait till the first has gone through the whole table?

Yes, for loops do yield, if you want them to not yield you can use task.spawn like this:

			for i,v in pairs(game.Teams.Home:GetPlayers()) do
			    task.spawn(function()
					wait(7)
					warn("Waited 7 seconds in the first loop")
				end)
			end
				for i,v in pairs(game.Teams.Away:GetPlayers()) do
			    task.spawn(function()
					wait(7)
					warn("Waited 7 seconds in the second loop")
				end)
			end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.