Can't add items to a list

Fix: I had a save file of the list that I would load in when the game started, that’s why I couldn’t change the list.

I have a list of the players best scores for my game. There was 3 floats in it but I needed another, so I added another, but I got a null reference error when I tried to get the fourth in the list. So I tried logging how many items were in it and it said 3. So I tried adding another, and it still said the same thing.

Here’s the script that contains the list.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerManager : MonoBehaviour
{
    public static List<float> personalBests = new List<float> {0, 0, 0, 0, 0};
}

Hi.

You should share the code for what you tried instead of describing it.

Array and list start from 0. So the last one is 3 if you have 4 items in your list.

Are you sure this isn’t the problem?

public static List<float> personalBests = new List<float> { 0, 0, 0 };

private void Start()
{
    // count: 3
    Debug.Log($"count: {personalBests.Count}");

    // add another 0
    personalBests.Add(0);

    // count: 4
    Debug.Log($"count: {personalBests.Count}");

    // last index: 3
    Debug.Log($"last index: {personalBests.LastIndexOf(0)}");
}