So look, here is a example on what I am kinda questioning for changing Values in a datastore. Can I use :SetAsync or do I use :GetAsync and then change the value?
local success, data = pcall(function()
return datastore:GetAsync(player.UserId) -- Getting data
end)
data.Cash = 123 -- Would that work?
Or do use datastore:SetAsync(player.UserId)
I am kind of thinking that it is :SetAysnc. But I just want to ask the community for now.
( yes i know this is a small topic but i just want to know. )
No. That wouldn’t work. :GetAsync() basically just returns a copy of the internal value you’re getting.
However, you can actually achieve what you’re trying to do using different methods. I won’t get too much into it, but you can load the player’s data when they join, put it into a table, and save that table when the player leaves. Now you can change that table while the player is ingame and it will save.
Popular datasaving resources like ProfileService use this method. It’s very efficient and I would recommend it.
I’ve been recommended to use ProfileService for a long time, as of right now I have made a big datastore script so I am not gonna restart, but the answer for me was really well. Thanks a lot!