I wrote a script with 7 different strings, and I made a loop to display them one at a time, but I can't get it to work. Did I write something in the wrong way?
Script
Label = script.Parent.TextLabel Tips = { "Tips n' Tricks", "Claim a Space Agency by touching the grey door in an empty tycoon", "Prioritize your cash income before buying optional upgrades", "Avoid combat with more powerful players, as you might end losing", "Button Colors", "Green : Increase your cash income", "Red : Optional upgrades" } while true do for i = 1, 7 do Label.Text = Tips[i] i = i + 1 wait(1) if i == 8 then i = 1 end end end
The "Tips" table contains every string, while the loop below it displays the text in a TextLabel. The script is below a ScreenGui, which is below StarterGui.
Thanks!
for
loops automatically move i
-- you really don't want to change i
inside of that loop:
while true do for i = 1, 7 do Label.Text = Tips[i] wait(1) end end
Alternatively, you could just use the while
loop and shuffle i
around like you were:
i = 1 while true do Label.Text = Tips[i] i = i + 1 if i > #Tips then -- Instead of `8`, `#Tips` -- That way you can add more tips without problems i = 1 end end
Perhaps a more idiomatic solution that either would be to use an iterator for loop:
while true do for _, tip in ipairs(Tips) do Label.Text = tip wait(1) end end