I just started working on datastores as I wanted to learn. I wrote up a code, and enabled API services. There are no errors in output, but when I change my values, they don't save can anyone help?
local DSService = game:GetService('DataStoreService'):GetDataStore('DataStore')
game.Players.PlayerAdded:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local leaderstats = Instance.new('IntValue', plr)
local savevalue = Instance.new('IntValue')
leaderstats.Name = 'leaderstats'
savevalue.Parent = leaderstats
savevalue.Name = 'Cash'
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved[1]
else
local NumbersForSaving = {savevalue.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Cash.Value}
DSService:SetAsync(uniquekey, Savetable)
end)

3 comments
How are you changing the values?
If its being done locally, or you're manually doing it then thats the issue. Has to be changed server side.
Read the guidelines before asking a question, specifically "Attempts should be your own work. Don't take a free model and expect us to fix it." Even if it is not from a free model, it isn't your own work. https://scriptinghelpers.org/help/community-guidelines This is a script copied from alvinbloxx: https://www.youtube.com/watch?v=tOOS9lMIYes