while i < 5 do wait(0.5) boot_text.Text = boot_text.Text .. " ." i = i + 1 if i == 5 then i = 1 boot_text.Text = "Booting" end end
I want this loop to stop after 3 cycles (meaning that once i has been reset to = 1, three times).
Is this possible?
You can use a nested for
loop to achieve this. Essentially, we have a crown loop call a second loop #n
time(s). You can also achieve better efficiency with this iteration function as it allows us to provide a numerical condition start, stop, step (optional)
which get's pushed into a parameter that we can use to keep track of our current iteration in the same behavior as creating a variable and incrementing it.
You can use the :rep()
method of String to determine how many trailing dot characters you wish to append to the text without having to add it piece by piece.
for _ = 1,3 do for i = 0,5 do boot_text.Text = "Booting"..('.'):rep(i) wait(.5) end end
Yes this is possible. Maybe the simplest way would be to add a cycle variable to count how many times the loop runs. I will insert this variable into your code. Actually let me adjust the code a little bit more.
local cycleCount = 0 while cycleCount < 3 do cycleCount = cycleCount + 1 for i = 1, 5 do wait(0.5) boot_text.Text = boot_text.Text .. " ." i = i + 1 if i == 5 then i = 1 boot_text.Text = "Booting" end end end
This should just count each time the while loop runs and stop when cycleCount gets to 3. It should also run the loop to get i to 5 and run the code for that as well. Hopefully this helped!