Why wont this saving module work?

So, im trying to make a better version of saving data, but i don’t know whats wrong with my script.

local https = game:GetService("HttpService")
local ds = game:GetService("DataStoreService")
local pds = ds:GetDataStore("PlayerData".."StudioTest_2")
local module = {}

module.NewPlayerData = {
	leaderstats = {
		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))
		print("DataFound /n "..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 NewPlayerData = {}
	local sessiondata = {}
	local function folderToDictionary(folder)
	    local dictionary = {}
	    for _, object in ipairs(folder:GetChildren()) do
	        if object:IsA("Folder") then
	            dictionary[object.Name] = folderToDictionary(object)
	        elseif object:IsA("ValueBase") or object.ClassName:match("Value") then
	            dictionary[object.Name] = object.Value
	        end
	    end
	    return dictionary
	end
	for _, v in pairs(Player:GetChildren()) do
		if v:IsA("Folder") then
			local new = folderToDictionary(v)
			table.insert(NewPlayerData,new)
		end
	end
	local dataX = https:JSONEncode(NewPlayerData)
	pds:SetAsync(Player.UserId,dataX)
	print(https:JSONEncode(NewPlayerData))
end

return module

Idk what im doing wrong here, i think its something about saving the data, when you don’t already have a data store it seems to work just fine, but when you rejoin i get something like this:


What am i doing wrong? (Also, to have a coin leaderboard do coins need to have their own data store?)
Thanks!

2 Likes

I see you have some prints in the script.
Can you please show us the output from those.

2 Likes