Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make that the table inside the table saves too?

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!

1 answer

I think you have to use a thing which saves it all, so you do it correctly next time.

4 comments

0

Try the datastore tutorial on youtube, it works perfectly.

0

yes a data store is what it's meant to do :)

0

This dosen't helps me.

0

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.