Basically, I'm trying to save 2 Datas, but it's not working, For Points
, it works, data is saved.
But for the Wins
, it doesn't why?
local DATASTORE = game:GetService("DataStoreService"):GetDataStore("DATASTORE") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local wins = Instance.new("IntValue") wins.Name = "wins" wins.Parent = leaderstats local Points = Instance.new("IntValue") Points.Name = "Points" Points.Parent = player local data local winsData local dataSaved, notSaved = pcall(function() data = DATASTORE:GetAsync(player.UserId.."-Points") winsData = DATASTORE:GetAsync(player.UserId.."-Wins") end) if dataSaved then Points.Value = data wins.Value = winsData print("Data Loaded") else print("Data not saved") warn(notSaved) end end) game.Players.PlayerRemoving:Connect(function(player) local dataSaved, notSaved = pcall(function() DATASTORE:SetAsync(player.UserId.."-Points", player.Points.Value) DATASTORE:SetAsync(player.UserId.."-Wins", player.leaderstats.Wins.Value) end) if dataSaved then print("Data Saved") else print("Data not saved") end end)
Instead of using 2 SetAsync and 2 GetAsync commands, put the variables in a table, like this:
local dataTable = { Points = Points.Value Wins = Wins.Value }
and use only 1 SetAsync and 1 GetAsync. The problem is that you're gonna deal with too many requests if the players join and you're setting 2 values, instead of 1. When you GetAsync, you can set the values from there, using this:
local success, err = pcall(function() DATASTORE:GetAsync(dataTable) end) if success then Points.Value = dataTable.Points Wins.Value = dataTable.Wins end