Recently, I had a discussion in the discord about whether or not to use :UpdateAsync or :SetAsync mainly because I did not need to access the previous values when saving the player's data. I have been mostly encouraged to use :UpdateAsync because it does not return a cached value. However, I don't need to know what the returned value is. Is it worth it to use :UpdateAsync which requires the creation of a function? Another thing that came up during that discussion was that I was creating two functions and using each only once. I am wondering when I should decide not to use functions and when to use functions. You see, I was setting an index in a table to the value returned by the functions and I felt that a function was easier. Here is the script:
local function saveData(player, retryCompatible)
local dataStoreService = game:GetService("DataStoreService")
local mainDataStore = dataStoreService:GetDataStore("generic")
local function createTableOfNames(objectList)
local newTable = {}
for i,v in pairs(objectList:GetChildren()) do
table.insert(newTable, v.Name)
end
return newTable
end
local function findEquipedTool(starterGear)
local starterGearList = starterGear:GetChildren()
if #starterGearList > 1 then
return false
else
for i,v in pairs(starterGear:GetChildren()) do
return v.Name
end
end
end
local replicatedStorage = game:GetSErvice("ReplicatedStorage")
local stats = replicatedStorage.Stats
local playerData = stats:FindFirstChild(player.Name)
local purchasedItems = playerData.PurchasedItems
local spaceCoins = playerData.SpaceCoins
local snow = playerData.Snow
local starterStuff = player.StarterGear
local equippedTool = findEquipedTool(starterStuff)
local listToSave = {}
local specialKey = "User-"..player.UserId
listToSave["Equipped"] = equippedTool
listToSave[purchasedItems.Name] = createTableOfNames(purchasedItems:GetChildren())
listToSave[spaceCoins.Name] = spaceCoins.Value
listToSave[snow.Name] = snow.Value
local success, message = pcall(
mainDataStore.SetAsync,
specialKey,
listToSave
)
if not success and retryCompatible then
local maxRetryAttempts = 3
local retryAttempts = 0
repeat
wait(5)
local success, message = pcall(
mainDataStore.SetAsync,
mainDataStore,
specialKey,
listToSave
)
retryAttempts = retryAttempts + 1
until retryAttempts == maxRetryAttempts or success
end
end
return saveData
I am wondering if I should use :UpdateAsync in the areas where :SetAsync is being used. Also, you can see the two functions I create that I only use once each. I would appreciate any insight you guys may have. Thanks!

4 comments
This is also just a general question about the convention of using functions.
please UpdateAsync erhggg
https://www.robloxdev.com/api-reference/function/GlobalDataStore/UpdateAsync
Don't arbitrarily use Update it has a purpose. It is not better, it is different!