I need help with Photon

I have followed this tutorial multiplayer fps serie from Expressed Unity especially this episode "

" and i need some help with it. I have followed the video till 23:30 and then all sort of things are broken. I get error saying “Can not Instantiate before client joined/created a room. State: Joining.” and i dont know what i should to do. I have checked all the codes and everything but for nothing. Do you have solution?

My MPManager code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.SceneManagement;

public class MPManager : MonoBehaviourPunCallbacks
{

    public GameObject[] EnableObjectsOnConnect;
    public GameObject[] DisableObjectsOnConnect;

    // Start is called before the first frame update
    void Start()
    {
        PhotonNetwork.ConnectUsingSettings();
        //PhotonNetwork.ConnectToRegion("eu");
    }


    public override void OnConnectedToMaster()
    {
        foreach(GameObject obj in EnableObjectsOnConnect)
        {
            obj.SetActive(true);
        }
        foreach(GameObject obj in DisableObjectsOnConnect)
        {
            obj.SetActive(false);
        }
        Debug.Log("Connected to photon");
    }

    public void JoinFFA()
    {
        PhotonNetwork.AutomaticallySyncScene = true;
        PhotonNetwork.JoinRandomRoom();
    }

    public override void OnJoinRandomFailed(short returnCode, string message)
    {
        CreateFFA();
    }

    public void CreateFFA()
    {
        PhotonNetwork.AutomaticallySyncScene = true;

        RoomOptions ro = new RoomOptions { MaxPlayers = 10, IsOpen = true, IsVisible = true };
        PhotonNetwork.CreateRoom("defaultFFA", ro, TypedLobby.Default);
       
        SceneManager.LoadScene("FFA");
    }
}

Movement code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
using Photon.Pun;

public class Movement : MonoBehaviourPun
{
    public KeyCode Left;
    public KeyCode Right;
    public KeyCode Forward;
    public KeyCode Backward;

    [SerializeField]
    private float MoveSpeed = 50;

    private Rigidbody body;
    private GameObject cam;

    // Start is called before the first frame update
    void Start()
    {
        body = GetComponent<Rigidbody>();
        cam = gameObject.transform.GetChild(0).gameObject;
        if (photonView.IsMine)
        {
            cam.SetActive(true);
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (photonView.IsMine)
        {
            float x = Input.GetAxis("Mouse X");
            float y = Input.GetAxis("Mouse Y");

            if (Input.GetKey(Left))
            {
                body.AddRelativeForce(Vector3.left * MoveSpeed, ForceMode.Impulse);
            }

            if (Input.GetKey(Right))
            {
                body.AddRelativeForce(Vector3.left * -MoveSpeed, ForceMode.Impulse);
            }

            if (Input.GetKey(Forward))
            {
                body.AddRelativeForce(Vector3.forward * MoveSpeed, ForceMode.Impulse);
            }

            if (Input.GetKey(Backward))
            {
                body.AddRelativeForce(Vector3.forward * -MoveSpeed, ForceMode.Impulse);
            }
            gameObject.transform.Rotate(new Vector3(0, x, 0));
            cam.transform.Rotate(new Vector3(-y, 0, 0));
        }
    }
}

And FFA/Free for all code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
using Photon.Pun;

public class FFA : MonoBehaviourPun, IPunObservable
{

    public float SpawnTime;
    float timer;
    bool HasPlayerSpawned = false;

    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        if(timer >= SpawnTime)
        {
            if (!HasPlayerSpawned)
            {
                PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity, 0);
                HasPlayerSpawned = true;
            }

            timer = 0;
        }
    }

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if(stream.IsWriting)
        {

        }else if (stream.IsReading)
        {

        }
    }
}

Hello, plz did you had any luck finding a solution ?

"Can not Instantiate before client joined/created a room. State: Joining."

This tells you that you can not call PhotonNetwork.Instantiate before the client is in a room. It’s still in state “Joining”, so you might have to wait. There are callbacks for this. OnJoinedRoom and so on.

This is also explained in the PUN Basics Tutorial.

Spawning in Update is maybe not a good idea. Update is for code that must run every frame.