local items = {
[1] = "Wood" -- or you can store Instance, for example 'game.ServerStorage.Wood'
[2] = "Apple"
[3] = "Box"
-- id can be either number or string, depends on what you want.
}
and then, whenever you want to access those items you can just do this,
local items = {
[1] = "Wood"
[2] = "Apple"
[3] = "Box"
}
local selectedItem = items[1] -- you can replace 1 with any id you want of course.
now, if you want to know what ID ‘Wood’ if assigned to then, you can make a loop and then whenever you have your target item, you check the index (or the key, actually), something like this,
local items = {
[1] = "Wood"
[2] = "Apple"
[3] = "Box"
}
local targetItem = "Wood" -- the item you want to check what the ID is.
local itemID -- you won't assign this since you don't have the value, yet.
for id, item in pairs(items) do
-- id is the key
if item == targetItem then
itemID = id
end
end
print(itemID) -- now you know what ID 'Wood' is.
I would recommend using Dictionaries since you can save a value, table, dictionary with a named key. this way you can save a value to ‘Wood’ like the amount that the play is holding for example
I wouldn’t recommend doing that especially when saving data - for example you misspell item name and want to change it without players loosing their data the answer is you can but it is more complicated than storing only the number index and adding name of the item inside of the table and then use it to display the name.
i save plr data in big arrays with complex data like that all the time and i think its more convenient and reliable knowing i dont have 2 tables one for names and one for values
I get what do you mean but it’s better to store number index instead of string because you can’t change the misspelled name without players loosing their data or adding extra piece of code to convert all existing data with misspelled name.