Create DoTween from for loop?

I’m trying to animate GUI values in my game that are stored as a list of integers. For this, I’ve tried to set up the following code using doTween.

    for (int i = 0; i < importantShoppingStats.Length; i++)
        if (oldShoppingStats_.statNumber != importantShoppingStats*.statNumber)*_

Debug.Log(“NEW TWEEN!”);
Tween valueTween = DOTween.To(() => (float)displayShoppingStats.statNumber, x => displayShoppingStats_.statNumber = (int)x, (float)importantShoppingStats*.statNumber, updateTime).SetOptions(false);_
oldShoppingStats _= importantShoppingStats;
This seems to not animate the values at all. However, if I do this, it seems to work fine for the one value I’m setting.
if(oldShoppingStats[0] != importantShoppingStats[0])
Tween valueTween = DOTween.To(() => (float)displayShoppingStats[0].statNumber, x => displayShoppingStats[0].statNumber = (int)x, (float)importantShoppingStats[0].statNumber, updateTime).SetOptions(false);

I don’t really understand what is happening differently when I put this if statement in the forloop that causes DoTween to act differently. I’ll be honest, this is my first lambda expression and I don’t have a very good grasp on that either. Any help would be greatly appreciated._

I hated this problem for years and forgot how I solved it in previous projects :smiley:

I just found out that if you wrap each DOTween.To method in a coroutine, it works well!

This should work:

IEnumerator Do(int i) {
             Tween valueTween = DOTween.To(() => (float)displayShoppingStats<em>.statNumber, x => displayShoppingStats_.statNumber = (int)x, (float)importantShoppingStats*.statNumber, updateTime).SetOptions(false);*_</em>

oldShoppingStats = importantShoppingStats*;*
yield return null;
Starting the coroutine without quotes will allow you to pass the iterator: