List won't keep making new items

this is supposed to be each collect = itemName + random amount and add it to list, but it does it once and 2nd time forgets first 1

public void TakeItem()
{
    itemName = gameObject.transform.name;
    itemAmount = Random.Range(1, 5);
    itemInfo = itemName + "(" + itemAmount.ToString() + ")";
    inventory.Add(itemInfo);
    foreach (string itemInfo in inventory)
    {
        newText.text = itemInfo.ToString() + " - ";
    }
}

Hello,

Is seems that the output you’re looking at is the text from some Text object newText. If that’s the case, since here you override its text field each time you iterate in the loop, you should instead add the new item to the string by changing the line to newText.text += itemInfo.ToString() + " - ";

Also, there’s no reason to use gameObject.transform.name, you can just use gameObject.name since a component has the name of the object it’s attached to. And lastly the variable itemInfo is a string so you don’t need to call .ToString()

Hope this helps,
Simon