Okay so I have this DataStore script that uses tables:
local KeyData = {
Key = "19AGS-JGCVM-IO9MK2",
Version = "1"
}
local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetDataStore("Key: "..KeyData.Key..", Version: "..KeyData.Version)
local PubData = {
["Coins"] = 0,
["Kills"] = 0,
["Level"] = 0
}
local ObjectData = {
["Class"] = "Warrior"
}
local NumberData = {
["Episode"] = 0,
["xpReq"] = 1000,
["xpProg"] = 0
}
game.Players.PlayerAdded:Connect(function(player)
local DataFromStore = nil
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
for n,v in pairs(PubData) do
local new = Instance.new("IntValue")
new.Name = n
new.Value = v
new.Parent = leaderstats
end
for n,v in pairs(ObjectData) do
local new = Instance.new("StringValue")
new.Name = n
new.Value = v
new.Parent = player
end
for n,v in pairs(NumberData) do
local new = Instance.new("NumberValue")
new.Name = n
new.Value = v
new.Parent = player
end
local suc, err = pcall(function()
DataFromStore = DataStore:GetAsync(player.UserId)
end)
if suc then
print("Getting Data For: " .. player.Name)
elseif err then
warn("Error Getting Data For: " .. player.Name)
end
if DataFromStore then
for n,v in pairs(DataFromStore) do
player.leaderstats[n].Value = v
player.n.Value = v
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local DataForStore = {}
for name, value in pairs(player.leaderstats:GetChildren()) do
table.insert(DataForStore, value)
DataForStore[value.Name] = value.Value
print(unpack(DataForStore))
end
DataStore:SetAsync(player.UserId, DataForStore)
end)
The script works well except for this part:
game.Players.PlayerRemoving:Connect(function(player)
local DataForStore = {}
for name, value in pairs(player.leaderstats:GetChildren()) do
table.insert(DataForStore, value)
DataForStore[value.Name] = value.Value
print(unpack(DataForStore))
end
DataStore:SetAsync(player.UserId, DataForStore)
end)
I'm getting the error of that you cannot store Arrays (tables) in DataStores and it can only accept valid UTF-8 characters. How do I fix this? Keep in mind it's just this part that has a problem and it's supposed to save player's data as normal.
To understand, DataForStore is a table variable that temporarily holds player data so it can save and load data. DataStore is a variable that has a key as Data to refer as so I can reset it whenever I want.

6 comments
Yes, I configured it to my preferred settings. I’ll try this solution out when I’m able to get on.
Removing that line did nothing but remove the error. My API services are also on
More specifically, the player data does not save. I put a print after line 74 but it doesn't print anything
Exactly that removed the UTF-8 error, ill edit my anwser to explain why its not saving
Ah right, I understand now. I'll see if I can do this with multiple players.
You can mark it now as awsner