I'm trying to save datastores with tables, the only error is "Cannot store Array in data store. Data stores can only accept valid UTF-8 characters." (Line 54)
Here is my entire script:
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local TestDataStore = DataStoreService:GetDataStore("emp43")
local data = {
["Steps"] = 0,
["Level"] = 1,
["Races"] = 0
}
Players.PlayerAdded:Connect(function(Player)
local DataFromStore = nil
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
for name, value in pairs(data) do
local new = Instance.new("NumberValue")
new.Name = name
new.Value = value
new.Parent = leaderstats
end
local s, e = pcall(function()
DataFromStore = TestDataStore:GetAsync("uid-" .. Player.UserId)
end)
if s then
print("Getting Data For: " .. Player.Name)
elseif e then
warn("Error Getting Data For: " .. Player.Name)
end
if DataFromStore then
for name, value in pairs(DataFromStore) do
Player.leaderstats[name].Value = value
end
print("Data Loaded For: " .. Player.Name)
else
print("Created New Data For: " .. Player.Name)
end
end)
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
TestDataStore:SetAsync("uid-" .. Player.UserId, DataForStore)
end)

7 comments
ok
it still isnt working
Did you adjust your script to your needed settings? If not, maybe check what's going wrong
The error went away now, but it isnt saving the data
Are your API Services on?
yes
I'm going to edit my answer with a script that simplifies everything and hopefully fufills your needs.