This piece of code from a big block seems to be the problem. It doesn't print out "Save 2"
local function SaveData(player) if player.userId < 0 then return end player:WaitForChild("leaderstats") wait() local leaderstats = {} for i, stat in pairs(player.leaderstats:GetChildren()) do if not stat:IsA("Folder") then print("Save 1") table.insert(leaderstats, {stat.Name, stat.Value}) end end player:WaitForChild("leaderstats"):WaitForChild("Rebirth") wait() for i, stat in pairs(player.leaderstats.Rebirths:GetChildren()) do print("Save 2") table.insert(leaderstats, {stat.Name, stat.Value}) end leaderboardData:SetAsync(player.userId, leaderstats) Print("Saved "..player.Name.."'s data") end
leaderstats folder: https://drive.google.com/file/d/1j1v2ZnDaCvP1ifK-H1XgtWIJffGFppzW/view?usp=sharing
I just got confused with the value "Rebirths" and the folder "Rebirth" sry everybody
in for i,v (save2) you have leaderstats.Rebirths but before for i,v you have WaitForChild("Rebirth") and not Rebirths
or
use this script and put all in 1 folder
local DataStoreService = game:GetService("DataStoreService") local playerData = DataStoreService:GetDataStore("PlayerData") game:GetService("Players").PlayerAdded:Connect(function(player) local playerUserId = "Player_"..player.UserId local data = playerData:GetAsync(playerUserId) local Folder = Instance.new("Folder", player) Folder.Name = "leaderstats" local XP = Instance.new("NumberValue", Folder) XP.Name = "XP" -- this is example local LVL = Instance.new("NumberValue", Folder) LVL.Name = "Levels" local XPN = Instance.new("BoolValue", Folder) XPN.Name = "XPN" if data then XP.Value = data["XP"] LVL.Value = data["Levels"] XPN.Value = data["XPN"] else XP.Value = 0 LVL.Value = 0 XPN.Value = true end end) local function create_table(player) local player_stats = {} for _, stat in pairs(player.leaderstats:GetChildren()) do player_stats[stat.Name] = stat.Value end return player_stats end game:GetService("Players").PlayerRemoving:Connect(function(player) local player_stats = create_table(player) local success, err = pcall(function() local playerUserId = "Player_"..player.UserId playerData:SetAsync(playerUserId, player_stats) end) if not success then warn("Could not save data") end end)