check players if their name contains in ArrayList or not

Hello, I was trying to add Players in ArrayList to show them and hide other players.

Here is the code:

public ArrayList Partynames = new ArrayList();
private bool inGroup = false;

private void FixedUpdate()
    {
       CheckMyPartyMembers();
    }

if (Input.GetMouseButtonUp(0))
  {
      if (Partynames.Contains(this.playerName) == false)
      {
          Partynames.Add(this.playerName);
          Debug.Log("added " + this.playerName);
           inGroup = true;

       }
       else {
                 Partynames.Remove(this.playerName);
                 Debug.Log("removed " + this.playerName);
                 inGroup = false;  
                }
}



private void CheckMyPartyMembers()
    {
        
        if (inGroup == true)
        {

            if (Partynames.Contains(this.playerName) == false)
            {
                Debug.Log("hide " + this.playerName);
                // Player not in my Party hide him.
                  // this not working
            }
            else
            {

                Debug.Log("show " + this.playerName);
                //Player in my party, show him
               // This only works
            }
       }
}

When i debug.log(this.playerName); , I get like this in console:
Player1
Player2
etc.

Also adding\Removing Players working fine, But the problem I don’t get “hide” in console. (Names of players that not in Array)

Anyone could tell me why hide players not working? I have tried a lot of methods.
Any help will be appreciated, Thanks

I don’t understand your code. As written Partynames will either contain this.playerName or be an empty arraylist. If it does not contain this.playerName then inGroup will be false, so CheckMyPartyMembers won’t output anything. Not sure what type this.playerName is, or where it gets changed if ever.

Hello thanks for your replay, (this.playerName) Its public variable for each player contains their network name. When i click on player i add them to the Array if i click again i remove them. But what i’m trying to do when i add someone to Array hide others, Like i said everything works fine but the hiding section is not working, I mean i don’t get (Debug.Log("hide " + this.playerName):wink: in console, The names not in the array to hide them.

Is this script attached to each player object? Because each instance of this script appears to get its own separate Partynames array then.

Yes its attached to each player, It seems working fine when i add them and remove them, i get their name printed in console, but the problem i can’t hide other players not in the list, Can you please figure this out with me? Because i tried much to solve this but nothing works with me. Anything want me to check or to do?