Moreover on getting player leaderstats and storing them on a string on DataStore.
local DataStore = game:GetService("DataStoreService"):GetDataStore("UserStats") game.Players.PlayerRemoving:connect(function(player) local key = "user_" .. player.userId DataStore:UpdateAsync(key, function(oldValue) local statData = "" for i, v in ipairs(player.leaderstats:GetChildren()) do statData = (statData.." "..v.Name..": "..v.Value) end return statData end) end)
How can I return these values stored in 'UserStats' when a player joins? I was thinking of some string.sub and getting certain Ascii characters, but I'm not sure where to go on from there.
local datastore = game:GetService("DataStoreService"):GetDataStore("UserStats") game.Players.PlayerRemoving:connect(function(player) player:WaitForDataReady() local key = "user_" .. player.userId datastore:UpdateAsync(key, function(oldValue) local a = player:WaitForChild("leaderstats"):GetChildren() for i= 1,#a do DataStore:SetAsync(a[i].Name..": "..a[i].Value) end end)
This loading the script I changed the script to my liking and found it easier to do. Sorry for the changes but should work.
local datastore2 = game:GetService("DataStoreService"):GetDataStore("UserStats") game.Players.PlayerAdded:connect(player) wait(20) player:WaitForDataReady() local key = "user_" .. player.userId if DataStore:GetAsync(key) ~= nil then local a2 = newplayer:WaitForChild("leaderstats"):GetChildren() for i = 1, #a2 do datastore2:GetAsync(stats2[i].Name) end end end)
This should work, hopefully.
~ Someone asks JSON I say "NO NOT AGAIN"