✓ Accepted answer
Use something like this:
local DSS = game:GetService("DataStoreService")
local datastore = DSS:GetDataStore("GeneralSaveData", "Players")
function generateDataKey(player)
local ret = "uid_" .. player.userId
return ret
end
function generateDataTable(player)
local dataTable = {
Points = player.leaderstats.Points.Value,
Wins = player.leaderstats.Wins.Value
}
return dataTable
end
function saveDataForPlayer(player)
local key = generateDataKey(player)
local data = generateDataTable(player)
datastore:SetAsync(key, data)
end
game.Players.PlayerAdded:connect(function(player)
player:WaitForDataReady()
end)
game.Players.PlayerRemoving:connect(function(player)
player:WaitForDataReady()
end)
game.OnClose = function()
wait(30)
end
You may have to edit it for your purposes. Hope this helps :)
4 comments
Thanks! Am I able to create a new variable not from the leaderboard in the DataStore?
yah you can create a seperate variable.
you don't need to wait for data to be ready
it just helps to make sure data is ready. but yes you don't really need it. it is just an extra protection.