Why does this increment by 2?

The object collides with the player, turns invisible, plays the particle, then increases the score based on the object’s color.

However, it increases yellowcount, bluecount, etc., by 2 instead of by 1 (same if it’s yellowcount += 1). Happens on the first frame of collision. Also happens if it’s OnTriggerExit2D.

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            renderer.enabled = false;
            particle.Play();

            switch (flagColor)
            {
                case 0: //yellow
                    score.yellowcount++;
                    break;
                case 1: //green
                    score.greencount++;
                    break;
                case 2: //blue
                    score.bluecount++;
                    break;
                case 3: //red
                    score.redcount++;
                    break;
            }
        }
    }

Check that your player doesn’t have more than one collider (possible child objects?) with the Player tag. Each one will trigger the code.

I can’t see any issue with that script that would produce this. I had a similar issue and it was because I had the script added twice in the scene so it did the calculations two times.