So I’m using ModuleScripts to save and load all of my datastores.
I have a function on a server script that detects when a user leaves and then saves the data in the module script…
This is my ModuleScript (save function)
function Arrest:SaveArrests(plr)
local Data = DataStore:GetAsync(plr.UserId)
DataStore:SetAsync(plr.UserId, Data)
end
First, a disclaimer: you should never have unprotected DataStore calls, as they can potentially fail and cause your script to error.
Onto the root of the problem, what your script is currently doing is:
When a player leaves the game, grab their data from the datastore, then set their data in the datastore to the data that we just grabbed from the datastore.
With this approach, no changes will ever be saved, because the data that you are saving is the data that was already in the datastore, not the data that was kept track of in the actual game.