Printing the index of a table ends up printing the object value as well as the index name

Hi all,
so I have been working on a custom admin for some time now and I am in the midst of making an admins command to list all admins in game. To do this I am iterating though my table of admins in which the player is the index and the value is their admin level.
However when I do this, this happens:
admins
So instead of printing just the player name it prints the object value as well.
This is the code I am using to iterate though the table:

		for i,v in pairs(Level)do -- Level is the table containing my admins
			print(i) 
			print(v)
		end

This is the code I am using to put a player into the admins table if they are an admin:

local Admins = {}


	if AdminLevel > 0 then -- Admin level is a numerical level corresponding to their admin level
		Admins[plr] = AdminLevel
	end

If anyone knows why this is happening or how to fix it I would appreciate it

There’s nothing wrong, you’re printing the index here:

so it’s printing?

Set the index as the player’s UserId or name if you don’t want this behavior.

Was this table passed through a RemoteEvent by chance? I had the same problem before. Roblox automatically converts instance indices to strings through RemoteEvents, which is why you’re seeing the weird print.

1 Like

Yes this was passed through a remote event, is this just a roblox issue for now then? How would I go about rectifying it?

You can index the table with the player’s name or userId instead, and get the player instance from there.

Read parameter limitations for remote events here:

1 Like

The problem I have at the moment is that I will have to rewrite my admin detection if I change the value of the index at the moment which doesn’t server much purpose of doing as of present. I guess Ill have to handle getting the list of players on the server now instead! Thank you though as I now know the cause of this

Reorganizing your code shouldn’t be too difficult. Save the indexes as the player’s userId instead, and then wherever the player is to be grabbed from the index, use GetPlayerByUserId.

For example, here is your code slightly modified.

	if AdminLevel > 0 then -- Admin level is a numerical level corresponding to their admin level
		Admins[plr.userId] = AdminLevel
	end
		for i,v in pairs(Level)do -- Level is the table containing my admins
			print(game.Players:GetPlayerByUserId(i)) 
			print(v)
		end

He is not passing a mixed table, all indicies are objects, none are integers.

They do automatically convert tables to strings in order to convert data into a format that can be sent over the network, however this is undone and all data should be there as it was on the server (as long as we are following the Parameter Limitations of course, which we are in this case.)

Sure using a string for the admin’s name is a valid workaround, but it doesn’t address what was causing the original problem or how to solve it.

After some testing, I’ve figured out that all tables with object indicies sent over to the client have the object replaced with <Instance> ObjectName, and this is not expected behavior (at least not documented anywhere that I see). I will be creating a bug report shortly and will link it at the bottom of this thread once posted.