Table[stringName] returning nil

Hello, I have a small problem regarding tables.
I have a table structured like that :

Table = {
   ["TEST"] = {},
   -- etc

Then I am trying to do Table["TEST"] but when printing it, it returns nil. Can you explain me why?

Fixed, I had to do :

Works fine for me. Likely a nesting issue or you indexed the wrong thing etc.

1 Like

Oh, it wasnt like that for me, in reality its a module script and then im sending some instance name but it doesn’t count as a string? So, just adding tostring works. Thank you anyways!

I’d probably look into that. Never take “it just works” as an answer or you may be hiding logical errors and bugs. Work out exactly what is being given and exactly what your table keys are.

typeof with print statements can help if you’re unable to identify it by simply looking at the code.

1 Like

Ok, lemme tell you my way of doing it :

Theres a module containing items with a function GetItemsToBeDisplayed(shopName) in the shop (depending on where the shop is opened). Then, whenever player touch a shop.PrimaryPart, I’m sending the shop name as the parameter which should be a string. The module receive it, search for TableOfItems[shopName] then return the table of items to be displayed.

My suspicion is that you’re sending an Instance - calling tostring on an instance will return its name, hence the solution.

Try putting a print(typeof(shopName)) on the line just before you do your tostring and if it prints Instance into the output window then you know that’s where the issue is. Hopefully that can then help you narrow down the original cause and clear up any other type issues in code that interacts with the shop name.

If you do wish to still use tostring, you can then place it in a sensible location, so that anywhere you’re referring to it as “shopName” will actually be a string.

1 Like

You’re totally right, I was sending the Instance, didnt even notice lmao

1 Like