Obtain the Key name instead of the Value when indexing a Dictionary

Alright, I’m currently making a warning service and I’m having a bit of trouble indexing the player’s current warns. The system is being coded so moderators will be able to view players warns even if they’re not online/in-game. The dictionary works like this

WarningDatabase = {

   [PlayerId] = {

       ["Player Disrespect"] = {"Moderator'sNameWhoWarned","DateOfWarn"}

   }

} 

The issue I’m currently having is the fact that when I index the players warns, I cannot get the Key name/reason. Any suggestions or methods to do this?

WarningDatabase[Player.userId] should work

If you loop through the table, you can get key/value from there. Something like:

local tab = WarningDatabase[PlayerId]
for reason, values in pairs(tab) do
  print("Player was warned for " .. reason)
  print("Player was warned by " .. values[1])
  print("Player was warned on " .. values[2])
end
15 Likes