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

Why do multiple loops inside a script seem to fail when other loops are running?

Asked by 9 years ago

Why do multiple loops inside a script (in this case a LocalScript) seem to fail when other loops are running?

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Probably because you're using endless loops and not putting coroutines

Say you have this in a script;

while wait(1) do
    print(math.random(1,5))
end

print('Derp')

'Derp' will never be printed, due to the endless loop above it.

So a way to fix? Coroutines.

coroutine.wrap(function()
    while wait(1) do
        print(math.random(1,5))
    end
end)()

print('Derp')
0
THankyou Blockeus 68 — 9y
Ad

Answer this question