Hi, I'm new to scripting and I'm trying to save a table, can someone tell me what's wrong with my script? I'm trying to save the data values in a table then have it load when you log back on, the output has no errors.
local DS = game:GetService("DataStoreService")
local playerData = DS:GetDataStore("PlayerData")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder", player)
folder.Name = "Stats"
local level = Instance.new("IntValue",folder)
level.Name = "Level"
local XP = Instance.new("IntValue",folder)
XP.Name = "EXP"
local maxXP = Instance.new("IntValue",folder)
maxXP.Name = "MaxEXP"
local stats = playerData:GetAsync(player.UserId)
if stats then
level.Value = stats["Level"]
XP.Value = stats["EXP"]
maxXP.Value = stats["MaxEXP"]
else
level.Value = 1
XP.Value = 0
maxXP.Value = 100
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local save = {}
for i, v in pairs(player.Stats:GetChildren()) do
table.insert(save, v.Value)
print(v)
end
playerData:SetAsync(player.UserId, save)
end)

3 comments
Why not use JSonEncode?
I've never heard of that
DataStore2 and ProfileWrapper also don't use that