Hello, i try to use UpdateAsync, but get this error:
ServerScriptService.DataStore:66: attempt to index nil with 'A'
this is the script in cuestion:
players.PlayerRemoving:Connect(function (player)
local FolderData = player.FolderData
datastoreservice:UpdateAsync(player.UserId, function(oldata)
local newdata = {}
local SUCCES, ERROR = pcall(function()
for Data, Value in oldata do
if type(Value) == "table" then
for Index, Val in Value do
newdata[Data][Index] = FolderData[Data][Index].Value
end
else
newdata[Data] = FolderData[Data].Value
end
end
end)
if SUCCES then
print("xd")
return newdata
else
print(ERROR)
return oldata
end
end)
end)
other times appear: ServerScriptService.DataStore:66: attempt to index nil with 'TrabajoActual'
and other times doesnt appear nothing
i tried clone player folder in serverstorage and concatenate name with FolderData … player.Name and after complete the update, destroy the folder but i get the same error
i belive that problem is here: FolderData[Data][Index].Value
but i dont know why
This most probably happens because when indexing the FolderData, the instance isn’t actually created. Can you try debugging print(FolderData:GetChildren()) before you apply the value?
You’re creating the newData table and looping over it. If the value is a table you loop over it again and apply to newdata[Data][Index]. However, the newdata[Data] is nil. Before you apply the main one, you have to do
newdata[Data] = {}
…to actually make it a table where you can define indexes
for Data, Value in oldata do -- You loop through the main table
if type(Value) == "table" then -- if the value's type is `table` then
for Index, Val in Value do -- loop through the `value`
newdata[Data] = {} -- have to define a table for the `Data` index or else it will stay `nil` which is why you're getting the error
newdata[Data][Index] = FolderData[Data][Index].Value -- THEN, we apply the `Index` index to the `Data` index
end
else -- if the type isn't a table, you don't need to make a table, just apply the value
newdata[Data] = FolderData[Data].Value
end
end