My game consists of a lot of statistics and instead of creating a datastore for each individual stat, I iterated them through a table and saved them to the datastore. The code works perfectly fine, but I’m trying to get away from using SetAsync when saving data. How would I do this with the method I’m using because every UpdateAsync tutorial I find is only setting one datastore value.
local function saveData(Player)
local PlayerFolder = game.ServerStorage.Players:WaitForChild(Player.Name)
local Stats = PlayerFolder.Stats
if RunService:IsStudio()then return end
local Data = {}
for _,stat in pairs(Stats:GetChildren())do
Data[stat.Name] = stat.Value
end
local success,err = pcall(function()
DataStore:SetAsync("UserId:"..Player.UserId, Data)
end)
if success then
print(Player.Name.."'s data has been successfully saved!")
else
warn("Something went wrong while saving "..Player.Name.."'s data!")
end
end