I would say you should absolutely be autosaving.
I have personally experienced data loss in @Quenty’s Whatever Floats Your Boat when there was no autosave. Servers would crash and I would lose data and it was sad. He was doing what you suggest (saving only on exit), and it did not work well. He has since implemented autosave, from what I can tell, and it’s all good now.
Autosaving should take up maybe two or three requests maximum, and that’s if you’re doing something complicated (like keeping all save history in an ordered data store). If you save once every 5 minutes then you should have no problem with # of requests regarding saves. In less datastore-heavy games, you can even save once every minute and still be completely fine.
You must be using datastores way more often than you think. Maybe you got a number wrong (e.g. 5
instead of 5*60
). You might also be using multiple keys/values per player. You only need to save to one key per player. Stick all of your data in one table so you only use one request when you save.
Here is what you should not do:
Data store error → assume default data → save default data
Here is what you should do:
Data store error → use default data, but never save it → retry datastore until it doesn’t error → Only save if their normal data loaded
If you’re losing data, I assume you’re doing the first one, which means you probably aren’t doing any error checking. Sometimes data stores stop working, but your players’ save data is still there, just inaccessible. You assume (incorrectly) that the player has no save data and overwrite it with the default data – causing data loss.
You need to be checking datastore calls for errors using pcall
. For example:
local data
local success, err = pcall(function()
data = datastore:GetAsync(tostring(player.UserId))
end)
if success == false then
warn("DataStore Error! Error: "..err)
-- Use default data and mark it as "do not save ever"
-- Retry data store every 30 or 60 seconds until it doesn't error
-- Once it doesn't error, give the player their normal data and clear the "do not save ever" flag
else
-- You have their data in `data`
-- Do whatever you need to with it
end