I did a menu and I want my player to be switched

I did a menu and I want a player to be switched between other 2 players and I don’t know how to do that . I did a script for switching but it doesn’t work ( my game has 3 rooms where u can choose in which one to play) when I choose a room it starts with the first player , not changing anything

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

public class SwitchScript : MonoBehaviour
{
    public GameObject avatar1, avatar2;
    int wichAvatarIsOn;
    void Start()
    {
        if (PlayerPrefs.HasKey("wichAvatarIsOn"))
        {
            wichAvatarIsOn = PlayerPrefs.GetInt("wichAvatarIsOn");
        }
        else
        {
            wichAvatarIsOn = 1;//Default to an avatarID you want as default
        }
        SwitchAvatar(wichAvatarIsOn);
    }

    public void SwitchAvatar(int avatarID)
    {
        switch (avatarID)
        {
            case 1:
                wichAvatarIsOn = 2;
                avatar1.gameObject.SetActive(false);
                avatar2.gameObject.SetActive(true);
                break;
            case 2:
                wichAvatarIsOn = 1;
                avatar1.gameObject.SetActive(true);
                avatar2.gameObject.SetActive(false);
                break;
            default:
                //Set a default avatar incase out of range and add a debug message
                Debug.Log("Avatar ID out of range: " + avatarID);
                wichAvatarIsOn = 2;
                avatar1.gameObject.SetActive(false);
                avatar2.gameObject.SetActive(true);
                break;
        }
    }
}

I don’t have a specific answer, because it looks like your problem is outside of this script (are you sure you’re getting the variable from playerprefs?). But, you’ve over complicated the task a bit. Instead of having two gameobjects and using a switch to activate / deactivate, just set up an array of prefabs GameObject[] avatars; which you can assign in the inspector. And then Instantiate the avatars[wichAvatarIsOn] you want.