[C#] 1 line code doesn't work

Hello, so here’s a challenge for you guys. Find an error and fix the code. Server is running only official resources + test resource on client side.

Here’s the whole code of test.net.dll:

using System.Threading.Tasks;
using CitizenFX.Core;

namespace test
{
    public class test : BaseScript
    {
		public test()
		{
			Tick += Loop;
		}

		private async Task Loop()
		{
			foreach(Player player in Players) { Debug.WriteLine(player.Name); }
			await Task.FromResult(0);
		}
	}
}

The problem is:
Player A connects to server (Console output for A: A)
Player B connects to server (Console output both: A, B)
Player B disconnects from server (Console output for A: A, B) = this is supposed to be only A because player B already disconnected

no need to spam the forum with another topic on the subject .

and you still finish your loop with a delay XD (isn’t you loop highlight in yellow in your visual studio ?) , you don’t listen people advice, whatever…

Well the other thread is clearly not interesting for people. So what advice I didn’t listen to? I tried everything you suggested and nothing worked. Nope, it’s not yellow.

you didn’t listen about the await Task.FromResult(0);

normaly if you look closer on visual studio you will see the name of your loop in yellow you telling you no await result , you have to put await Task.FromResult(0); instead of your delay as i already explain you. that will not fix your thing but it will run the loop properly .

for your probleme i already gave you a native who will normaly fixe your probleme but you said this is different way of doing it , you want the normal way. there is no normal way , just the one who is working.

Ok I’m gonna edit the code with Task.FromResult(0);. But it’s not going to help in any way.

The native you gave me wouldn’t help with this problem, even if it worked.

I’m not sure what the problem could be with this, but I assume you just want a list of the active players?

What I have done is just add the Player.Handle to an ArrayList when they connect, and remove it when they drop.

1 Like