table.FindNext Help

Hi! Could someone tell me why this is only using the playermodel after its current one?

local FindNextTable = table.FindNext( PossibleClothes )
local FindPrevTable = table.FindPrev( PossibleClothes )

function SelectModel( ply )
ply:SetModel( FindNextTable )

obviously i am calling it but just not included the code

table.FindNext needs two arguments: the table and the current value. It’s probably better to get the index of the current model and set the previous/next model to the value at the index above and below the current one. If you are not already iterating using

ipairs somewhere within your code, then you could use

table.KeyFromValueto find the current key.

Quite uncertain what you are trying to do. What are your keys as? It says table.FindNext/Prev is decapricated so you should use something else.
Why not just do something like

local current = 0;
for i, v in pairs( PossibleClothes ) do
    if( v == ply:GetModel() ) then
        current = i;

local next, prev = false;
if( #PossibleClothes < current ) then
    next = PossibleClothes[ current + 1 ];

if( current > 1 ) then
    prev = PossibleClothes[ current - 1 ];

if( next ) then
    ply:SetModel( next );

Don’t use table.FindNext and table.FindPrev. They’re unreliable.

Instead you should be using a circular-queue sort of setup.

local curIndex = 0
local queue = { "Model 1", "Model 2", "Model 3" }

function SelectModel( ply )

	curIndex = curIndex + 1

	if curIndex > #queue then
		curIndex = 1

	ply:SetModel( queue[ curIndex ] )


Use ipairs instead of pairs to preserve the order.