I have a table with models named redtycoon, bluetycoon and greentycoon. how would I find them by name? I tried this and it doesn't work. .Name doesn't work either
for i,v in pairs (tycoons) do if i == "RedTycoon" then print("red") end if i == "BlueTycoon" then print("blue) end if i.Name == "GreenTycoon" then print("green") end end
In this case, "i" stands for the index (or key!) of the value (v) you are looking for. Since this is a dictionary, there are a couple ways to reference them (but I can't list all of them as Roblox has built-in API to search dictionaries within the hierarchy of the game)
This means you can do this:
for i, v in pairs(tycoons) do print(i) end
But I'm assuming you want to access a specific tycoon and not iterate through each one. In that case, you can do this for dictionaries, also known as tables that use non-numerical indices (which include, but are not limited to, Enum values, strings, table reference pointers, userdata, etc):
local tycoons = {} tycoons["RedTycoon"] = "Hello." print(tycoons["RedTycoon"]) -- I recommend this for indices that include spaces. print(tycoons.RedTycoon) -- This is nearly the same exact thing as the above, except you cannot have indices start with a digit. -- OUTPUT: -- >>Hello. -- >>Hello.
You search for them just like you do with normal tables, except the value type is different.