How can I get a value from a table?

I am making an admin system, and there are different admin ranks, in order to do this, I am using a table to assign a value to the admin’s user id:

local admins = {
	{
		ID = 1578920035,
		Rank = 5
	},
}

This has been working for me, but now it has stopped working and if I try printing the ID or Rank value using (print(admins.ID) for example, it prints nil, I can’t find anything about this on the wiki or forum.

1 Like

With the way you have this setup, you can not just do “print(admins.ID)”. You instead need to do something like this (if this example is your real layout):

for _, v in pairs(admins) do
  print(v.ID)
end
3 Likes

I am using that for the actual admin script bit yet it doesn’t seem to work.

1 Like

You can also index it like this: admins[1].ID. However, can you show the rest of your code please?

1 Like
game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		for _, id in pairs(admins) do
			if plr.UserId == id.ID then

Then it is just the admin commands.

1 Like

Well, you can first of get the entire admins count by doing #admins then you can index any of the number that is lower than the count. This way should work. Also you could do it with for i = 1, #admins

2 Likes

Check under (if plr.UserId == id.ID) if it prints anything.

1 Like

Nope, doesn’t come up with anything.

I just tested your code in a baseplate to see if it printed anything when I joined (after changing the ID to my ID) and it worked perfectly fine?

Yes for some reason I created another separate script in the same baseplate and it worked, I am going to search through all the code to try and find the source.

1 Like

Ok that is good. Good luck with your system! :slight_smile:

Thanks! :grin: It was going so well until I ran into this little snag.

I seemed to have found the code responsible for it, the point of the code is to insert an int value into the player to make it easier with getting the player’s rank, but for some reason it is crashing the admin script.

--------------------------------------------
--Inserting the admin rank into the player--
--------------------------------------------
game.Players.PlayerAdded:Connect(function(player)
	local rankValue = Instance.new("IntValue", player)
	rankValue.Name = "Rank"
end)

while wait() do
	for i, id in pairs(admins) do
		local player = game.Players:GetPlayerByUserId(id.ID)
		player.Rank.Value = id.Rank
	end
end

Oh, you can do that part a lot differently. First off, you do not need a while wait() loop for this. You can instead do something like this:

1 Like

Thanks so much, now I can actually start making some more commands.

Oh, no problem. Good luck with that :slight_smile:

1 Like