So im trying to be more efficient with my work, and so instead of having a lot of data stores, i can just use one. The loading in seems to work fine, but i don’t really know how i would convert a folder with values in it into a table. Could someone help me?
local https = game:GetService("HttpService")
local ds = game:GetService("DataStoreService")
local pds = ds:GetDataStore("PlayerData")
local module = {}
module.NewPlayerData = {
Currency = {
Coins = 0;
Gems = 0;
};
AllTime = {
TotalCoins = 0;
TotalGems = 0;
TotalCoinsCollected = 0;
TotalGemsCollected = 0;
TotalDamage = 0;
TotalKills = 0;
TotalBossKills = 0;
TotalDistanceTraveled = 0;
TotalTimePlayed = 0;
};
Stats = {
CoinsMultiplier = 0;
GemsMultiplier = 0;
DamageMultiplier = 0;
};
CharacterStats = {
Walkspeed = 16;
Jumppower = 50;
};
About = {
Banned = nil;
Bans = 0;
Warnings = 0;
};
};
function module.SetUp(Player)
local data
if pds:GetAsync(Player.UserId) ~= nil and pds:GetAsync(Player.UserId)~="" then
data = https:JSONDecode(pds:GetAsync(Player.UserId))
else
data = module.NewPlayerData
end
for _, v in pairs(data) do
if typeof(v)=="table" then
local folder = Instance.new("Folder",Player)
folder.Name = _
for a, x in pairs(v) do
if tonumber(x)~=nil then
local val = Instance.new("IntValue",folder)
val.Name = tostring(a)
val.Value = x
end
end
else
print("Non table")
print(v)
end
end
end
function module.Pack(Player)
local data = {}
local sessiondata = {}
for _, v in pairs(Player:GetChildren()) do
if v:IsA("Folder") then
for a, x in pairs(v:GetChildren()) do
end
end
end
for _, v in pairs(module.NewPlayerData) do
if typeof(v)=="table" then
end
end
print(https:JSONEncode(Player))
end
return module
Thanks