local DataStoreService = game:GetService("DataStoreService") local playerData = DataStoreService:GetDataStore("PlayerData") local function playerAdded(player) local TycoonSaveFolder = Instance.new ("Folder") TycoonSaveFolder.Name = "TycoonSaveFolder" local leaderstats = Instance.new ("Folder") leaderstats.Name = "leaderstats" local money = Instance.new("IntValue") money.Name = "Money" money.Parent = leaderstats local points = Instance.new("IntValue") points.Name = "Points" points.Parent = leaderstats local rebirth = Instance.new("IntValue") rebirth.Name = "Rebirths" rebirth.Parent = leaderstats leaderstats.Parent = player local playerUserId = 'Player_'..player.UserId local data = playerData:GetAsync(playerUserId) if data then money.Value = data["Money"] points.Value = data["Points"] rebirth.Value = data["Rebirths"] else money.Value = 0 points.Value = 0 rebirth.Value = 0 end end local function create_table(player) local player_stats = {} for i, stat in pairs(player.leaderstats:GetChildren()) do player_stats[stat.Name] = stat.Value end return player_stats end local function onPlayerExit(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 game.Players.PlayerAdded:Connect(playerAdded) game.Players.PlayerRemoving:Connect(onPlayerExit)
everything is working except for the
local TycoonSaveFolder = Instance.new ("Folder") TycoonSaveFolder.Name = "TycoonSaveFolder"