Unity photon multiplayer teams

Hello, I’m trying to figure out how to create my script for spawning players and assignment to the team. When the player joins, player will be added to the team with less players, if the players are the same player will join the red team. When I tested my script but the players always join the red team, I’d be glad for any help.

 const string VERSION = "v0.0.0.2";

    //Teams
    public int playersOnBlue;
    public int playersOnRed;


    public Transform[] spawnPointsBlue;
    public Transform[] spawnPointsRed;

    public Transform point;

    void Start()
    {
        PhotonNetwork.ConnectUsingSettings(VERSION);
    }

    void OnJoinedLobby()
    {
        RoomOptions roomOptions = new RoomOptions() { IsVisible = false, MaxPlayers = 4 };
        PhotonNetwork.JoinOrCreateRoom("room", roomOptions, TypedLobby.Default);
    }


    void OnJoinedRoom()
    {
        if (playersOnBlue >= playersOnRed)
        {
            GameObject player = PhotonNetwork.Instantiate("PlayerRed", point.position, point.rotation, 0);
            photonView.RPC("AddPlayers", PhotonTargets.AllBuffered, 0);

        }
        else if (playersOnRed >= playersOnBlue)
        {
            GameObject player = PhotonNetwork.Instantiate("PlayerBlue", point.position, point.rotation, 0);
            photonView.RPC("AddPlayers", PhotonTargets.AllBuffered, 1);
        }
        else if (playersOnRed == playersOnBlue)
        {

            GameObject player = PhotonNetwork.Instantiate("PlayerRed", point.position, point.rotation, 0);
            photonView.RPC("AddPlayers", PhotonTargets.AllBuffered, 0);
        }
    }

    [PunRPC]
    void AddPlayers(int blue)
    {
        if(blue == 1)
        {
            playersOnBlue++;
        } else
        {
            playersOnRed++;
        }
    }

the error is because they have to assign the photon script “PunTeams” to the gameobject

Ok i figured it out. I used photon bulit-in teams script. If anyone Interested, here is the script:

 const string VERSION = "v0.0.0.2";

public Transform[] spawnPointsBlue;
public Transform[] spawnPointsRed;

void Start()
{
    PhotonNetwork.ConnectUsingSettings(VERSION);
}

void OnJoinedLobby()
{
    RoomOptions roomOptions = new RoomOptions() { IsVisible = false, MaxPlayers = 4 };
    PhotonNetwork.JoinOrCreateRoom("room", roomOptions, TypedLobby.Default);
}

void OnJoinedRoom()
{
    if (PunTeams.PlayersPerTeam[PunTeams.Team.blue].Count >= PunTeams.PlayersPerTeam[PunTeams.Team.red].Count)
    {
        GameObject player = PhotonNetwork.Instantiate("PlayerRed", spawnPointsRed[PunTeams.PlayersPerTeam[PunTeams.Team.red].Count].position, spawnPointsRed[PunTeams.PlayersPerTeam[PunTeams.Team.red].Count].rotation, 0);
        PhotonNetwork.player.SetTeam(PunTeams.Team.red);

    }
    else if (PunTeams.PlayersPerTeam[PunTeams.Team.red].Count >= PunTeams.PlayersPerTeam[PunTeams.Team.blue].Count)
    {
        GameObject player = PhotonNetwork.Instantiate("PlayerBlue", spawnPointsBlue[PunTeams.PlayersPerTeam[PunTeams.Team.blue].Count].position, spawnPointsBlue[PunTeams.PlayersPerTeam[PunTeams.Team.blue].Count].rotation, 0);
        PhotonNetwork.player.SetTeam(PunTeams.Team.blue);

    }
    else if (PunTeams.PlayersPerTeam[PunTeams.Team.red].Count == PunTeams.PlayersPerTeam[PunTeams.Team.blue].Count)
    {
        GameObject player = PhotonNetwork.Instantiate("PlayerRed", spawnPointsRed[PunTeams.PlayersPerTeam[PunTeams.Team.red].Count].position, spawnPointsRed[PunTeams.PlayersPerTeam[PunTeams.Team.red].Count].rotation, 0);
        PhotonNetwork.player.SetTeam(PunTeams.Team.red);
    }
}

I also get this error. Did you get this fixed?