Simple Variable Modification Not Working

Hi, I am making a simple 2d fighting game and health will decrease on one character while not doing so on the other. While printing health (2 different tests) the broken player will post this:8903055--1218318--upload_2023-3-25_15-48-46.png
and the working one will post this:
8903055--1218321--upload_2023-3-25_15-50-33.png
The only difference is the order in which they will show the health. My script is this:

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


public class PlayerCombat : MonoBehaviour
{
    bool iscollided = false;
    public TextMeshProUGUI player1;
    public TextMeshProUGUI player2;
    int player1health = 100;
    int player2health = 100;
    public int playerNumber;

    void Update()
    {
        if (Input.GetButtonDown("FirePrimary"+playerNumber.ToString()) && iscollided)
        {
            AttackPrimary();
        }
        player1.text = player1health.ToString();
        player2.text = player2health.ToString();
    }

    void AttackPrimary()
    {
        if(playerNumber == 1)
        {
            player2health -= 5;
        }
        if(playerNumber == 2)
        {
            player1health -= 5;
        }
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        iscollided = true;
    }
    private void OnCollisionExit2D(Collision2D collision)
    {
        iscollided = false;
    }
}

All my code is the same for both players; no errors appear in the editor.

When you take a second player’s health, like here

if(playerNumber == 1)
{
     player2health -= 5;
}

This does not mean that the second player’s health has changed in the script. After all, you simply change the private variable of one object, which does not affect the amount of health in the script of the second player.

Most likely it will work if you make these variables public static to make them “common” for the class.