issue involving playerprefs

I have a “datapack” hidden in each of my levels, the system remembers per level if the artifact has been taken and if so it disables the artifact when a player replays it but i also want to keep track of the total amount taken, the system almost works there’s just 1 small issue: When i finish the level with the first datapack, in the menu it says: 1, this is correct. but when i do it with the 2nd, it says 3, with the 3rd it says 4, 4th says 5 etc i don’t understand why and thus can’t fix it here’s the code:

function OnTriggerEnter(other : Collider) {
    if(other.CompareTag("DataPacket")){
    pickedUpDataPacket = 1; 
    Destroy(other.gameObject);
    gameObject.Find("DatapackFound").guiText.enabled = true;
    yield WaitForSeconds (1.5);
    gameObject.Find("DatapackFound").guiText.enabled = false;
    }
    if(other.CompareTag("Finish") && pickedUpDataPacket == 1){
    PlayerPrefs.SetInt("DataPackLevel" + levelindex.ToString(), 1);
    //if(!PlayerPrefs.HasKey("totalDatapacks")){
    //PlayerPrefs.SetInt("totalDatapacks", 1);
    //} else {
    PlayerPrefs.SetInt("totalDatapacks", (PlayerPrefs.GetInt("totalDatapacks")+1));
    } 
    }
//}

i already commented a part out, i believe this was also part of the issue.

and part of a 2nd script:

if(datapacktotal){
    if(PlayerPrefs.GetInt("totalDatapacks") > 0){
        findText.text = "Collected:" + PlayerPrefs.GetInt ("totalDatapacks");
    }

Thanks in advance :slight_smile:

My guess is that your OnTriggerEnter function is getting called (i.e. triggered) more than you think it is – for example, at the start of a level, perhaps. Add a Debug.Log there, or use a breakpoint, so you can see exactly when it’s getting invoked.