When the masterclient try to leave room its work if it 's not the masterclient doesnt work

Nadoc
Nadoc

I want that when a player leaves the game the other players also leave

when the player leaving is the masterclient all players leave

when it 's not the masterclient the others leave it but not him

I DONT UNDERSTAND WHY



 


Answers

  • You need to implement OnPlayerLeftRoom, not OnPlayerDisconnected.

    That should be all.

  • Its doesnt work with OnPlayerLeftRoom its the same problem

    if i m the masterclient its work allthe players return to lobby scene

    if i m not the masterclient , the masterclient return to lobby scene and others stay in the same scene


      public void BackToLobby()
      {
       StartCoroutine(LoadLobby());
      }
    public override void OnPlayerLeftRoom(Player otherPlayer)
      {
    
        StartCoroutine(LoadLobby());
    
      }
    
      public IEnumerator LoadLobby()
      {
        PhotonNetwork.Disconnect();
        while (PhotonNetwork.IsConnectedAndReady)
          yield return null;
    
        SceneManager.LoadScene("Lobby");
     
      }
    


  • I just wait 2 sec after leaving room and then load scene.

    It worked for me

    private LeaveRoom()
    {
               PhotonNetwork.LeaveRoom();
               yield return new WaitForSeconds(2f);
               Debug.Log("No Maps Left");
               SceneManager.LoadScene("Lobby", LoadSceneMode.Single);
    }