Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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 comment

1

Works amazing thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.