I have code that looks like the following:
foreach (var player in Players.ToList())
{
try
{
// something asynchronous that could take several hundreds of ms to complete
}
catch
{
}
}
During that loop, a player could disconnect, because in the loop I trigger client events and delay until the client triggers a response server event.
I’m wondering why isn’t there something like player.IsConnected
. It would help.
1 Like
Cookay
August 17, 2020, 4:07am
2
Assuming in your case player is the serverId of the player, then you could use GetPlayerName(player), if it’s nil then your player is disconnected
1 Like
MrAjax
August 17, 2020, 7:22pm
4
what if player is timeout ? or in re-connection , will this do the job ?
Cookay
August 17, 2020, 10:05pm
5
Hmmm, no idea try it, when i want to TriggerClientEvent on a specified client i check with GetPlayerName before and it does work.
Another thing would be to listen on the event playerDropped, that depends on your needs
2 Likes
MrAjax
August 17, 2020, 10:08pm
6
well when a player is in re-connection playerDropped won’t call ! even tho will test it tomorrow
Flawws
August 18, 2020, 10:03am
7
You can check the players ping. If it’s above 0, then assume they’re connected?
1 Like
MrAjax
August 19, 2020, 3:04pm
8
player ping has a few seconds delay so not a solution
MrAjax
August 22, 2020, 5:23pm
9
Cookay:
GetPlayerName
not works either when the player is re-connecting
ABHIS
January 28, 2021, 5:44pm
10
Ping players manually using events. I suggest using TaskCompletionSource to make it awaitable. Something so trivially done in script doesn’t really need a feature request.