I want to save tables in Data Store!
For instance, I want Items within a player’s Inventory will be saved in the data store by using a table If the player left.
I know How I make script running when the player leaves and saving her Inventory.
But I don’t know how to save tables in Data store.
local tab = {Cash = 4, Coins = 10};
DataStore:SetAsync(key, tab)
-- of course this is just an example of how you would save data and not what I'm telling you to literally do.
UpdateAsync considers the older value before saving, it’s dangerous to use Set() at times where you need the previous value.
Might wanna avoid SetAsync and use UpdateAsync generally if you can. Here’s why.
@roasted_shrimps for future reference, you can save almost anything as long as it’s not something userdata like objects. So tables, dictionaries, and arrays will work when saving. Strings, numbers, whatever like that.
Just for clarity, @roasted_shrimps, there’s a process called serialization, you can serialize data that is not in the right format to be saved itself (vector3 values for example), technically not just anything can be saved to a DataStore.
For reference, don’t JSONEncode tables when saving them to a DataStore thinking they can’t be saved themselves, anything that needs to be saved is turned into a string format itself (only strings can be saved to the DataStore), so JSONEncoding it would just increase the amount of characters you’re saving.
I would like to also clarify that what I mean is just based on normal datastore saving so any serialization is possible just that you’re well technically saving still tables, dictionaries, arrays, strings, numbers, etc that is normally accepted but in replacement of something that can’t be saved or loaded normally. Serialization is definitely useful in saving object data.
EDIT: Oops guess you were replying to the original poster, this reply is now useless
cc @ArtFoundation, @XxELECTROFUSIONxX using Set is fine. Mass-replacing Set with Update ruins the whole point of actually updating the value. You can use Set just fine if you need to force data or if you really just don’t care about the old value. You use Update when you actually need the previous data
Yes, you’re correct, though I would say it’s a good habit to know to use Update as well since I wouldn’t want to encourage always using Set for every use case.