GetPlayers() returning empty table


I don’t know if I’m just missing something here or what.

AddEventHandler("chatMessage", function(player, playerName, message)
	if message == "test" then
		local players = GetPlayers()

returns an empty table every time even though I’m clearly on the server typing test in the chat.


What’s the rest of the code look like? I’ve just tested this (copy pasted what you had) with no problems.


It’s suppose to return a table of all the players id’s right?

The code I gave you is all I got, the resource is called test, and it has only one server side lua file called test with that code in it. It seems when I join and type test, it will show one player in the table with an id of 1. If I disconnect and rejoin then type test again, now it will still show one player in the server but I will still have the id 1 instead of 2 as it shows on the scoreboard. This is literally the only resource I have loaded, everything else is the same as when I downloaded the server.



I don’t know how all the internals work. sorry. As far as I know, the IDs in the GetPlayers() array should work for server-side interactions with clients (e.g. TriggerClientEvent) and other server-side functions that require the players ID (e.g. GetPlayerName).


Isn’t this what you are looking for?
From scoreboard script if I am not wrong.

function GetPlayers()
  local players = {}
  	for i = 0, 31 do
      if NetworkIsPlayerActive(i) then
				table.insert(players, i)
	return players


That’s for client side. He’s calling the built-in server-side function.


Ahh ok, sorry then for misunderstanding. :slight_smile: