ClientRPC firing intermittently

Hey!

I have an extremely strange issue that I am trying to debug and hopefully someone can notice where I am going wrong.

Here is some code to help you get the idea but the gist of it is that this code is for syncing the quests when a player joins a game. This way is not the best thats for sure but I would like to make it functional before I start refactoring.

So this piece of code will occur when the first player has started hosting and they have loaded into the first level.

using MLAPI;
using MLAPI.Messaging;
using RPG.Dto;
using System.Collections.Generic;
using UnityEngine;

public class NetworkStateManager : NetworkBehaviour
{
    private static NetworkStateManager Instance;

    private void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }
        else
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
    }

    private void Start()
    {
        NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnected;
    }

    private void OnClientConnected(ulong clientID)
    {
        OnClientConnectedServerRpc(clientID);
    }

    [ServerRpc(RequireOwnership = false)]
    private void OnClientConnectedServerRpc(ulong clientID)
    {
        if (IsHost == false)
        {
            return;
        }

        Debug.Log($"Syncing quests to the new client with ID:{clientID}");

        List<Quest> quests = QuestManager.Instance.GetStartedQuests();
        List<QuestDto> questsData = new List<QuestDto>();

        foreach (Quest quest in quests)
        {
            QuestDto dto = new QuestDto()
            {
                NpcNetworkID = quest.NpcNetworkID,
                QuestID = quest.QuestID,
                GoalDescription = quest.CurrentGoal.Description,
                GoalAmount = quest.CurrentGoal.AmountCurrent
            };

            questsData.Add(dto);
        }

        QuestManager.Instance.SyncQuestsClientRpc(questsData.ToArray());
    }
}

In the QuestManager here it will loop through each given NPC until we find the correct quest and then through each goal until we have the correct goal and set the correct amounts.

    [ClientRpc]
    public void SyncQuestsClientRpc(QuestDto[] quests)
    {
        Debug.Log("Beginning quest sync with host");
        StartedQuests.Clear();
        CompletedQuests.Clear();

        foreach (QuestDto quest in quests)
        {
            NetworkObject network = GetNetworkObject(quest.NpcNetworkID);
            Npc npc = network.GetComponent<Npc>();

            Quest currentQuest = null;

            while (true)
            {
                npc.StartNextQuestClient();

                currentQuest = npc.GetCurrentQuest();

                if (currentQuest.QuestID.Equals(quest.QuestID) == false)
                {
                    npc.CompleteQuestClient();
                    CompletedQuests.Add(currentQuest);
                }
                else
                {
                    StartedQuests.Add(currentQuest);
                    break;
                }
            }

            while (true)
            {
                QuestGoal goal = currentQuest.CurrentGoal;

                if (goal.Description != quest.GoalDescription)
                {
                    for (int i = 0; i < (goal.AmountRequired - goal.AmountCurrent); i++)
                    {
                        goal.OnEvent(null, goal.RequiredID);
                    }
                }
                else
                {
                    goal.AmountCurrent = quest.GoalAmount;

                    break;
                }
            }
        }
    }

This is no so much about this code itself but about the formatting of when my network methods are called for example as I attached a debugger to the built game as well as some logs and sometimes the ClientRPC just does not fire.

Feel free to ask any questions and I will do my best to answer.

Bump! I am still stuck on this issue and it is a bit of a blocker unfortunately. Does anyone have any ideas?