How to get the value using a key in a table?

Hello !

  1. What do you want to achieve?
    I want to get the value of a key in a table: Exemple:
local Table = {
["World 1"] = "Volcano";
["World 2"] = " Island";
["World 3"] = "Sea"
  1. What is the issue?
    So, for exemple, i want to get “Island” by searching “World 2” in the table but not by searching everything using for i, v in pairs() do end

  2. What solutions have you tried so far?
    I tried to use for i, v in pairs() do end, but then, using this, i need to use if /// then /// elseif /// end
    but the script is getting weird if i have more than 50 world because it means i need to spam 50 times elseif in my script

So, i read many topics about tables, but nothing is answering my question: everyone use

for key, value in pairs(testDictionary) do
	print(key, value)

Thanks for helping !
Have a good day, bye !

Can’t you just do Table[key] to get the value?

If you wanted Volcano, do Table["World 1"]


Oh , yes, thanks you, i was reading this at the same time ^^

Tysm, Have a great day !

1 Like