Also basiclly it saves only one table but not the table inside the table yeah how could I fix? The output only shows a error at loading cause it has nil value cause the innertable got not saved. How to fix?
local DS = game:GetService("DataStoreService")
local PetDS = DS:GetDataStore("PetDataStore1")
local PetsTable = {}
local AUTOSAVE_INTERVAL = 60
game.Players.PlayerAdded:Connect(function(Player)
local PetsFolder = Instance.new("Folder")
PetsFolder.Name = "Pets"
PetsFolder.Parent = Player
local key = Player.UserId
print(key)
PetsTable = PetDS:GetAsync(key)
if PetsTable then
print(PetsTable)
PetsTable = game:GetService("HttpService"):JSONDecode(PetsTable)
for _,p in pairs (PetsTable) do
local In = Instance.new("IntValue")
In.Name = p["Name"]
In.Parent = PetsFolder
In.Value = p["Value"]
end
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
PetsTable = {}
local key = Player.UserId
print(key)
for _,i in pairs (Player.Pets:GetChildren()) do
if i then
table.insert(PetsTable,i.Name)
PetsTable[i.Name] = {}
table.insert(PetsTable[i.Name],"Name")
table.insert(PetsTable[i.Name], "Value")
PetsTable[i.Name]["Name"] = i.Name
PetsTable[i.Name]["Value"] = i.Value
print(PetsTable[i.Name]["Name"])
end
end
PetsTable = game:GetService("HttpService"):JSONEncode(PetsTable)
print(PetsTable)
PetDS:SetAsync(key, PetsTable)
warn("Saved!")
end)
Thanks for answers!

4 comments
Try the datastore tutorial on youtube, it works perfectly.
yes a data store is what it's meant to do :)
This dosen't helps me.
I have seen examples which encode tables in json and store them for later use. this was used to store user creations in a build a base type game.