Hello,
I am working on the datastore for my game, and I am trying to figure out how to load a huge system of tables, create instances of them in a folder in the player, go through all instances in folder, and then save all the data. Here is what I have so far:
local http = game:GetService("HttpService")
local ds = game:GetService("DataStoreService")
local database = ds:GetDataStore("test-database")
local ToSave = {
["heyThere"] = {"abcdefg","StringValue"},
["n o way"] = {72,"NumberValue"},
["test"] = {{
["wow"] = {"zers","StringValue"},
["how"] = {5,"IntValue"}
},"table"},
["WeNeedToGoDeeper"] = {{
["yes"] = {{
["yippee"] = {{
["I wonder how deep we can go :thinking:"] = {34,"IntValue"}
},"table"}
},"table"}
},"table"}
}
local function constructPlayerData(player)
local pdata = Instance.new("Configuration")
pdata.Name = "PlayerData"
pdata.Parent = player
local function createTable(ptable, pparent)
for index, value in pairs(ptable) do
print(index)
print(value)
if value[2] ~= "table" then
local newval = Instance.new(value[2])
newval.Name = index
-- Add datastore loading here
newval.Value = value[1] -- This is just the default
newval.Parent = pparent
else
local newFolder = Instance.new("Configuration")
newFolder.Name = index
newFolder.Parent = pparent
createTable(value[1], newFolder)
end
end
end
createTable(ToSave, pdata)
end
local function deconstructPlayerData(player)
local pdata = player:FindFirstChild("PlayerData")
local TBSaved = {}
local function deconstructTable(ptable, pparent)
for _, instance in pairs(ptable:GetDescendants()) do
if instance:IsA("Folder") then
TBSaved[instance.Name] = {instance.Value, type(instance)}
else
TBSaved[instance.Name] = {thisIsWhereIAmStuck, "table"}
deconstructTable(instance, pparent)
end
end
end
deconstructTable(pdata, pdata)
end
game.Players.PlayerAdded:Connect(constructPlayerData)
game.Players.PlayerRemoving:Connect(deconstructPlayerData)
Image of the creation working:
The part that I am struggling with is where the undefined variable thisIsWhereIAmStuck
is. Does anyone know how I would go about doing what I want?
Best regards,
– Ham