I have a very strange problem with adding variables to the table
I had such a script, and it worked despite the fact that I wrote the ‘name’ instead of the ‘Name’
function save(plr)
local items={}
for i,v in pairs(plr.Inventory:GetChildren())do
table.insert(items,v.price.Value,v.name) -- [150]='itemName'
end
if #items>0 then
local s,err=pcall(function()
itemsDS:SetAsync(player.Name..'-'..player.UserId,items)
end)
if s then else print(err) end
end
end
I even tried with item[v.price.Value]=v.Name but everything is the same, and if the items are repeated with this method, they will be saved as one
script to add items:
local itemsdata
local s,err=pcall(function()
itemsdata=itemsDS:GetAsync(player.Name..'-'..player.UserId)
end)
if s then else print(err) end
for price,name in pairs(itemsdata)do
--[[
add item script, but they are not saved because the table size is zero
Nothing is loaded except for those items that are already written to the datastore before this bug
--]]
end
and now, since about three or four days ago, this function has stopped working. I did not change anything, everything from the inventory is written to the server. Works
print(item.price.Value,item.Name)
but not written to the table
Maybe I changed something in some service, or something else. Help me solve the problem
and then, you can use the # operator (or table.getn() alias).
Also, player.Name..'-'..player.UserId as a DataStore key is very bad.
Why do you need a player name in the key?
When someone changes a username, they’re gonna lose the data.
And one more thing: if s then else print(err) end can be replaced with if not s then print(err) end
Writing something to the table does not work, only writing a number or name works, two at once doesn’t. I did not dare to make dictionary tables in dictionary tables because I thought that it would be difficult to read them from there.
I’ll try to do with this method
But still, I’m wondering why the writing of two values to the table stopped working, before that everything was fine
The subject is bool value and it contains data values such as price (number value), type (string value), rarity (number value), and etc. I don’t know why, but I found it so convenient
And by the way, a very important question, do you know how to transfer my old save system to the new one? More precisely, from dictionary tables to dictionary tables in dictionary tables