Make it so that every time the player clicks the button, a counter is incremented. Whenever that counter goes above 5 (which is the number of indices in destination, set it back to 1.
A quick and simple way of making it go back to 1 every time if goes over time is to use the modulo % operator. The modulo operator gets the remainder of a division (i.e. 7%5 evaluates to 2).
local counter = 1
counter = counter%5 + 1
So what's happening?
I initialized the counter to 1. This is because the first index in an array is always 1.
Whenever I click the button, I first use the modulo operator on counter (so that, when it is currently 5, it rolls back to 0)
Lastly, I add 1 to counter.
If I were to print the values of counter every time I click the button, it would appear like this:
1
2
3
4
5
1
2
3
4
5
...
This pattern would carry on forever. Your final script would appear like this:
local destinations = {
"Dest1";
"Dest2";
"Dest3";
"Dest4";
"Dest5";
}
local counter = 1
script.Parent.MouseClick:connect(function()
counter = counter%5 + 1
script.Parent.Parent.TextThing.TextLabel.Text = destinations[counter]
end)
1 comment
I'm your biggest fan <3