local DataStoreService = game:GetService("DataStoreService") local dataStore = DataStoreService:GetDataStore("TheData") local warns = game.StarterGui.Warnings local warnings = warns.Frame.WarnText game.Players.PlayerAdded:Connect(function(player) local stats = Instance.new("Folder",player) stats.Name = "leaderstats" local coins = Instance.new("IntValue",stats) coins.Name = "Coins" coins.Value = 100 local levels = Instance.new("IntValue", stats) levels.Name = "Levels" levels.Value = 1 local exp = Instance.new("IntValue", stats) exp.Name = "Exp" exp.Value = 0 local mycafeval = Instance.new("NumberValue", stats) mycafeval.Name = "OwnsCafe" mycafeval.Value = 0 local data local success, err = pcall(function() data = dataStore:GetAsync(player.UserId) end) if success then coins.Value = data[1] levels.Value = data [2] exp.Value = data [3] else print("Player has NO data!") warnings.Text = "No data to be saved!" end end) local function saveData(player) local tableForSaving = { player.leaderstats.coins.Value, player.leaderstats.levels.Value, player.leaderstats.exp.Value } local success, err = pcall(function() dataStore:SetAsync(player.UserId, tableForSaving) end) if success then print("Data has been saved") if success then print("Data has been saved") warnings.Text = "Data has been saved!" else print("Failed To Save Data") warnings.Text = "Data has not been saved!" warn(err) end end game.Players.PlayerRemoving:Connect(function(player) -- When a player leaves local success, err = pcall(function() saveData(player) -- Save the data end) if success then print("Data has been saved") warnings.Text = "Data has been saved!" else print("Data has not been saved!") warnings.Text = "Data has not been saved!" end end) game:BindToClose(function() -- When the server shuts down for _, player in pairs(game.Players:GetPlayers()) do -- Loop through all the players local success, err = pcall(function() saveData(player) -- Save the data end) if success then print("Data has been saved") warnings.Text = "Data has been saved!" else print("Data has not been saved!") warnings.Text = "Data has not been saved!" end end end)
This is my DataSave script but it will not save
Idk sure but you should try to separe the data save from leaderstats. It should work then.