(I’m not an expert at DataStores so forgive me for this)
The code I used to reset the data from my DataStores isn’t working. It never seems to work with UpdateAsync and always returns an error message. If I use SetAsync, it works fine, but I’m afraid spamming would cause the requests to clog up.
Script (in ServerScriptService)
game.ReplicatedStorage.resetDataStoreValues.OnServerEvent:Connect(function()
print("hasran")
local success, errorMessage = pcall(function()
cheeseEnding:UpdateAsync("hasCheeseEnding", false)
timesShoplifted:UpdateAsync("timesShoplifted", true)
end)
if success then
print("Reset DataStores")
elseif errorMessage then
warn(errorMessage)
end
end)
In your case you should be using SetAsync since you’re not transforming the existing data. SetAsync is a write operation whereas UpdateAsync is both a read and a write operation.
GlobalDataStore:SetAsync() is best for a quick update of a specific key, and it only counts against the write limit. However, it may cause data inconsistency if two servers attempt to set the same key at the same time.
GlobalDataStore:UpdateAsync() is safer for handling multi-server attempts because it reads the current key value from the server that last updated it before making any changes. However, it’s somewhat slower because it reads before it writes, and it also counts against both the read and write limit.
My game is going to be a single-player game with multiple servers. So I don’t want any data inconsistency on the player’s part as I would hate to ruin the experience.
My game has endings, which have to be saved on true and false values. Many people (probably not) will most probably be triggering the DataStore saves at once. This script is for resetting the values of the DataStores.
So I don’t want any data inconsistency on the player’s part as I would hate to ruin the experience.
I think you’ve misunderstood the documentation you’ve quoted.
is safer for handling multi-server attempts because it reads the current key value from the server that last updated it before making any changes.
UpdateAsync is only going to be more favorable than GetAsync in cases where either multiple servers are attempting to write to the same datastore key or a datastore key’s existing value needs to be transformed.
For simple Boolean value assignments SetAsync will suffice.