[C#] GetNumPlayerIndices returns 0

I wish to print to console the number of players on the server every x seconds, right now this prints 0, but when I join, it’s still 0. Have I forgotten something or is there a better way/native

using System;
using System.IO;
using System.Threading.Tasks;
using CitizenFX.Core;
using static CitizenFX.Core.Native.API;

namespace ServerDOJ
{
    public class DOJScriptServer : BaseScript
    {
        int playerCount = GetNumPlayerIndices();

        public DOJScriptServer()
        {
            Tick += OnTick;
        }

        private async Task OnTick()
        {
            Console.WriteLine(playerCount);
            await Delay(10000);
        }
    }
}

You never call GetNumPlayerIndices again after declaring the playerCount variable.

Move the playerCount declaration inside your OnTick

This fixed it, thank you very much

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.