How to insert a value into a string in a table

Hello, This is probably a really simple thing to do but I’m trying to save a inventory of string values so I’m saving a table but so far it only saves the name of the value instead of the name and value so I’m wondering how I can save the value under the name.

image

1 Like

dont use table.insert if you have other index for the data instead of int, because table.insert works with only integers

just do like this:
for i, v in pairs(Inventory:Get()) do
Inventory[v.Name] = v.Value
end

thats all

4 Likes

Hey sorry I’ve got a follow up question, when retrieving data from that table I can only seem to get the value. Is it possible to get the name as well?
image
image

2 Likes

That is what the “i” in for i,v is.

3 Likes

Sorry to disturb you again but I’ve encountered an issue, when a player has multiple of the same item it only saves one. I’m thinking this could be due to them all having the same name in the table. Is there a way around this?
image

2 Likes

Use the instance as the key instead:

Inventory[v] = v.Value

If you wanted to get the name of the instance:

-- Assume this is inside of the for loop
print(i.Name)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.