Cycling through Multi-state Box states

I am new to velo and don’t completly understand it, so I ask that you have pacientce with me.

I am trying to change the state of a multi-state box every 5 seconds to create a loop of taglines playing on my site header. Here is the code I have tried to use, but nothing happens when I preview the code. I have double checked the ID names multipule times.

$w.onReady(function () {
  const multiStateBox = $w('#Titleloop');
  const states = ['State1', 'State2', 'State3', 'State4'];
  let currentIndex = 0;

  function cycleStates() {
    multiStateBox.value = states[currentIndex];
    currentIndex = (currentIndex + 1) % states.length;

    setTimeout(cycleStates, 5000);
  }

  cycleStates();
});

Thank you in advance!

!!! —> setTimeOut() <---- is NOT —> setInterval() <---- !!!

You will need something like this…

$w.onReady(()=> {
    const maxRounds=5;
    const stateSwitchTime=5000;
    //---------------------------------
    const myMSB=$w('#Titleloop');
    //---------------------------------
    // Counter variable to track the number of rounds
    let counter = 0; 

    function intervalFunction() {counter++;
        console.log('Interval function triggered. Round:', counter);
        if (counter===maxRounds) {
            // Clear the interval when counter reaches 5-rounds.
            clearInterval(intervalId);
            console.log('Interval stopped after 5 rounds.');
        }       
        else {console.log("Changing MSB-STATE...ROUND-"+counter)
            myMSB.changeState('State'+counter);
        }
    }
    const intervalId = setInterval(intervalFunction, stateSwitchTime);
});

!!! Try to get it to work. This is just an example !!!