Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do i make it so a script prints all players and if they are nil?

Asked by 9 years ago

I was wondering how i could make a script that prints all the people in the server and if they are nil tell me one of my friends made this one:

local PlayerName='iiXynx';
local inGame,Player=pcall(function()return(game:service'Players'[PlayerName]);
end);
if(not inGame)then print(string.format('Player %s is not in the Players instance.',PlayerName));
else print(Player,' is here.');
end;

but this only shows me if one person is in or not and it also doesnt tell me if they are nili was just wondering if anyone knows how?

                                                          ~Thanks, Derpy~

1 answer

Log in to vote
0
Answered by
Diitto 230 Moderation Voter
9 years ago

Just use NetworkServer, and check if each player is not parented to Player.

local Players={};

for _,Player in next,game:service'NetworkServer':children() do
    if( Player:isA'ServerReplicator'and Player:getPlayer() )then--// Checks if they are a fully joined player, and if they are actually a player.
        Players[Player:getPlayer().Name]={
            Player,
            Player.Parent~=game:service'Players',
        };
    end;
end;

In the Players table, the first argument would be the Player, then the second would be if they are "nil."

To print them, just do,

if( Player:getPlayer().Parent~=game:service'Players' )then
    print(string.format('%s is not ingame.',Player:getPlayer().Name));
end;
1
Works amazing thanks! xDerpyDinox 5 — 9y
Ad

Answer this question