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

When should I be including a wait() inside of a for loop?

I was wondering if it would cause problems to have a couple of for loops in a row which have to sort through about 50 items. Would I need to include a wait() in that scenario or will I be fine to leave it out?

2 comments

0

Should be fine

0

What about with larger data sets? What would be a limit after which I should use wait()? I ask because I use a few crucial for loops that I don't want to error.

1 answer

✓ Accepted answer

as long as there's a definite end, you shouldn't have to put a wait() in. for example, this loop would NEED a wait(),

while true do
	wait()
end

while this doesn't:

local f = workspace:GetChildren()
for i = 1, #f do
	f[i].Name = "chungus"
end

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