For some reason, when saving, the datastore attempts to store an array, which outputs the following error:
00:15:35.817 - Unable to save for 7z99. Error: 104: Cannot store Array in data store. Data stores can only accept valid UTF-8 characters.
Why, and is there a solution?
Here's my datastore script:
local DS = game:GetService("DataStoreService"):GetDataStore("a")
game.Players.PlayerAdded:Connect(function(player)
variablePlayer = player.Name
local folder = Instance.new("Folder",player)
folder.Name = "inventoryfolder"
inventory = {}
inventory.Name = "inventory"
local dataKey = "userkey_"..player.UserId
local data
local success,errormsg = pcall(function()
data = DS:GetAsync(dataKey)
end)
if success then
if data ~= nil then
for i,v in pairs(data) do
print(i,v)
local i2 = Instance.new("StringValue", folder)
i2.Value = v
end
else
print("Player is new.")
end
else
warn("Error when retrieving data for "..player.Name..". Error: "..errormsg)
folder.Value = nil
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success,errormsg = pcall(function()
for i, v in pairs(player.inventoryfolder:GetChildren()) do
table.insert(inventory, i, v.Value) -- Inserts each value from the inventoryfolder folder which is the child of the player.
print(v.Value)
end
DS:SetAsync("userkey_"..player.UserId, inventory) -- Attempts to save the table, but can't.
end)
if not success then
warn("Unable to save for "..player.Name..". Error: "..errormsg)
end
end)
