I have table problem

local tag = {
["potion"] = "abc"
}
for i, v in pairs(tag) do
print(i) -- potion
print(v) -- abc
print(typeof(tag)) -- table
end

table.insert(tag,"bag","accessory") -- its says I cant use string for number pos.

how I can do this:
before:

tag = {}

use command…

after:

tag = {
["potion"] = "abc"
}

with table.insert or same way?

1 Like

You can just write tag["bag"] = "accessory". Most table functions use only numeric indexes, not string keys.

1 Like

Table insert uses 3 things, a table, an optional index to insert it in, and the thing you want to insert. You’re giving it a string for a number position

To do what is needed, just do how @BenMactavsin mentioned

1 Like

I think you can do this:

tag['postion'] = 'abc'
1 Like