How to generate and manage the number of items on a map in the same room

Options
Dear all,

I am trying to generate randomly the items such as star, heart, diamond, coin...on a map with the parameter - the maximum number of items in one room.
In my method, I used the master client ( PhotonNetwork.IsMasterClient) of a room to run the function to generate the items. Only the master client generate and manage the number of items on a map. if the master client leaves a game then other player is assigned as the master client using OnMasterClientSwitched() method and continue generate and manage the number of items.
However, the issue is when the master client leaves the game, I cannot transfer the parameter - ItemNumber that is to count the number of items on the map to new master client. And it is always to start from 0.
Do you know any way to transfer the parameter from the master client to new master client when it leaves the game? Or any way to generate and manage the number of items on a map in the same room?
This is my code:
void Update()
{
if (photonView.IsMine && PhotonNetwork.IsMasterClient)
{
StartCoroutine(spawnRandomItems());
spawnWait = Random.Range(spawnLeastWait, spawnMostWait);
}
}

private IEnumerator spawnRandomItems()
{
yield return new WaitForSeconds(startWait);
while (ItemNumber < maxItemNumber)
{
int randItemType = Random.Range(0, 4);

Vector3 spawnPosition = new Vector3(Random.Range(-17f, 17f), 1f, Random.Range(-17f, 17f));
Quaternion spawnRotation = Quaternion.Euler(-90, 0, 0);
PhotonNetwork.InstantiateSceneObject(spawnItemObjects[randItemType].name, spawnPosition, spawnRotation);
ItemNumber++;

yield return new WaitForSeconds(spawnWait);
}
}

I also used OnPhotonSerializeView(), but it also didn't work.
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(ItemNumber);
}
else if (stream.IsReading)
{
ItemNumber = (int)stream.ReceiveNext();
}
}
Thank you so much!!!!!