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

How do I loop a function X number of times?

I want to loop a function, but not infinitely. Let's say I wanted to do it 5 times.

function spawnmob()
end

spawnmob()
spawnmob()
spawnmob() -- not what i want to do
spawnmob()
spawnmob()

Is there a way to loop functions X number of times?

1 answer

✓ Accepted answer

Use a return statement :)

local o = 0
return
o = o + 1
spawnmob()
wait (1) ---Replace with number of seconds within each spawn (IMPORTANT)
until o = 5 ----Replace 5 with whatever

Best of Luck

4 comments

0

Thanks.

0

Actually, have a problem with that. See, I'm using it in a function. The function is fired by a loop that checks for something. It doesn't work in a function.

0

Fixed it myself using wiki. Still thanks, this led me to the wiki.

0

@better or use a for loop since that's what for loops are for

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