I originally thought this was an issue with datastore, but upon further examination I determined that the data was saving, but the Rubles value from the player removing function is getting the wrong Rubles Value. For instance, when I set the Rubles value to 25, and then I click stop, even though the Rubles Variable is 25, the script still outputs 10 when printing savetable. The reason I know this to be true is because I edited the line "local Savetable = {plr.leaderstat.Rubles.Value}" to "local Savetable = {plr.leaderstat.Rubles.Value+2}". And next time I load the game, I have 12. So I'm wondering why incorrect data is being retrieved here.
local DataStoreService = game:GetService('DataStoreService') local moneyStore = DataStoreService:GetDataStore('Djmaster444TestStore03') game.Players.PlayerAdded:connect(function(plr) plr:WaitForChild(plr.Backpack.Name) -- Define variables local uniquekey = 'id-'..plr.userId local leaderstat = Instance.new('NumberValue', plr) local savevalue = Instance.new('NumberValue') leaderstat.Name = 'leaderstat' savevalue.Parent = leaderstat savevalue.Name = 'Rubles' savevalue.Value = 10.00 -- GetAsync local GetSaved = moneyStore:GetAsync(uniquekey) print(GetSaved[1]) if GetSaved then savevalue.Value = GetSaved[1] else local NumbersForSaving = {savevalue.Value} moneyStore:SetAsync(uniquekey, NumbersForSaving) end end) game.Players.PlayerRemoving:connect(function(plr) saveData(plr) end) function saveData(plr) local uniquekey = 'id-'..plr.userId local Savetable = {plr.leaderstat.Rubles.Value} moneyStore:SetAsync(uniquekey, Savetable) end
you could try my datastore model: https://www.roblox.com/library/2790189297/Datastore Heres how it works
--You must publish the game for it to work local Mod = require(game.ServerStorage.StatsHandler) Mod:GetFolderName("leaderstats") Mod:GetStarterData({Rubles = 10}) game.Players.PlayerAdded:Connect(function(plr) Mod:LoadStarterData(plr) Mod:LoadData(plr) end) game.Players.PlayerRemoving:Connect(function(plr) Mod:SaveData(plr) end)