Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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?

0
Should be fine INOOBE_YT 387 — 5y
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. User#21908 42 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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
Ad

Answer this question