Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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

0
Try the datastore tutorial on youtube, it works perfectly. DEVLogos 8 — 5y
0
yes a data store is what it's meant to do :) extremeparkrider 0 — 5y
0
This dosen't helps me. GodOf_Lua 25 — 5y
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. extremeparkrider 0 — 5y
Ad

Answer this question