How to cycle through a table? (ui/gui)

Heyo, ui noob here. I’m trying to create an avatar editor and I just hit a road bump.
Let’s say I want to have 5 hair options. I assume the best way to go about cycling through the different choices would be by creating a table.

local hairs = { hair1, hair2, hair3, hair4, hair5}

But I’m not quite sure how to cycle through them properly for a gui. I tried researching it but the only resources I found were for ui grids & scrolling frames. I’d greatly appreciate it if any of you guys could post suggestions or links to resources. Thanks in advanced!

Keep track of a number:

local whichHair = 1

Then if you click the right button just do

whichHair = whichHair + 1
gui.Text = hairs[whichHair].Name -- or whatever

If you click the left button just do - 1 instead. I’ll leave it to you to add checks to make sure it doesn’t go lower than 1 or higher than #hairs.

1 Like