- Home /
The player who leaves second is not being able to create or join room - Unity Photon Network
I am facing this issue and it's stopping my progress. I am making a chess game with multiplayer. I was successful in creating a room and make other player join, but once the game is over and one of the players leave the game then the player who leaves second is not being able to create a room or join a new room for a new game and gets an error "JoinRandomRoom failed. Client is on GameServer (must be Master Server for matchmaking) but not ready for operations (State: Leaving). Wait for callback: OnJoinedLobby or OnConnectedToMaster." Doesn't matter if the player was a master client or not, if they are leaving second? they won't be able to join or create a new room.
once the game is over and I am switching back to menu, I am checking couple of things in mainmenu like, 1. Am i still in a room? result is always false 2. Am i even connected to server? result is always true
Here is the code that works in main menu
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class NetworkController : MonoBehaviourPunCallbacks
{
private void Start()
{
if(PhotonNetwork.InRoom)
{
Debug.Log("why am i In a room in start?");
PhotonNetwork.LeaveRoom();
}
if (PhotonNetwork.InLobby)
{
Debug.Log("why am i In a Lobby in start?");
PhotonNetwork.LeaveLobby();
}
if (PhotonNetwork.IsConnected)
{
Debug.Log("We are connected to the " + PhotonNetwork.CloudRegion + " server! (Btw calling from start)");
}
else
{
Debug.Log("We are not connected to the " + PhotonNetwork.CloudRegion + " server! (Btw still calling from start)");
}
Connect();
}
private void Update()
{
if (!PhotonNetwork.IsConnected)
{
Connect();
}
}
public override void OnConnectedToMaster()
{
Debug.Log("We are connected to the " + PhotonNetwork.CloudRegion + " server!");
}
public override void OnLeftLobby()
{
Connect();
}
private void Connect()
{
// PhotonNetwork.JoinLobby();
PhotonNetwork.ConnectUsingSettings();
}
}
Here is the code that works after user presses button for main menu
public void OnHome()
{
if (PhotonNetwork.InRoom)
{
OnClickDisconnect();
goHome = true;
}
else
{
SceneManager.LoadScene("Main Menu");
}
}
public void OnQuit()
{
OnClickDisconnect();
Application.Quit();
}
public void OnClickDisconnect()
{
PhotonNetwork.LeaveRoom(); /// With only this line, local player will leaveRoom and join MasterServer, which I don't want. (In this example, he will reconnect to the room)
PhotonNetwork.LeaveLobby();
}
public override void OnLeftRoom()
{
if(goHome == true)
{
goHome = false;
SceneManager.LoadScene("Main Menu");
}
}
Can you please help me solve this problem? I am going crazy! No matter what i tried, the second player just won't be able to join or create a new room.
Answer by elmtim · Dec 30, 2020 at 11:33 AM
Oh I had the same Problem. it turned out, that my Problem was , that whily try leaving the timescale was 0. By setting time. Time.timeScale = 1 is worked ;D
Answer by elmtim · Dec 29, 2020 at 11:42 PM
Oh I had the same Problem. It turned out, my problem was , that whily try leaving the timescale was 0. By setting time. Time.timeScale = 1 is worked ;D