Why is the "col" objects tag not changing?

Hi!
I want both the gameobject that the script is attached to to change tag to “0”(upon collision) – but also the gameobject that it is colliding with, col, to change. Unfortunately col does not change tag. The col object also has this script attached to itself.

    void OnCollisionEnter2D (Collision2D col) {
        if(col.gameObject.tag[1] == gameObject.tag[1] && gameObject.tag != "0" && gameObject.tag != "4" && col.gameObject.tag[0] != gameObject.tag[0]) {
            gameObject.tag = "0";
            col.gameObject.tag = "0";
            joint.connectedBody = col.gameObject.GetComponent<Rigidbody2D>();
            joint.enabled = true;
            valenceText.text = gameObject.name + System.Environment.NewLine + gameObject.tag;
        }
    }

your if statement is pretty horrific
indexing a tag is just picking letters from the tag
if your tags are just “0”, “4”, etc then tag[1] will be out of range
whereas, if your tag is “ball” then tag[1] = the letter ‘a’

I am well aware but that has nothing to do with my question.

Well there’s a few things you can do to figure out why it’s not working as expected

        void OnCollisionEnter2D (Collision2D col) {
Debug.Log("Collision happened between " + gameObject.name + " and " + col.gameObject.name);
Debug.Log("Their tags are " + gameObject.tag + " and " + col.gameObject.tag);
       //...
        }

That way you can see what’s going on, and then follow your logic through