So in my game, I use a datastore script that weaves through a folder with values in them, that save when changed, but, I do not like it to become clustered / filled up. Does anyone have any idea or method I could consider to solve this?
One possible idea I had was storing a table inside of a string value but I don’t know I’d go about doing that.
Datastore methods are throttled so you want to limit how often you call them. If your values change often you may want to switch to a time based autosave. I use FastBitBuffer to pack a large amount of data into a single buffer string to save to datastore.
First of all, I suggest making use of 1 datastore to handle almost (if not all) of your game’s data. You can save all of your data into 1 table and set that table to your datastore key (eg:SetAsync(key,table)). You can also modularize your system to have a cleaner design and improved organization. You should not call requests to your datastore as soon as your values are changed since it will ratelimit you eventually and begin to drop requests that you send instead of processing them as expected (30+ requests). If you are having problems with data loss or don’t want to risk it, you can autosave data with a time interval of 60 seconds in a loop. Also if you want to “put a table into a string” that’s just JSON which you can use by utilizing the HTTPService provided by Roblox with the methods [HS:JSONDecode() / HS:JSONEncode]
You can store tables, arrays, dictionaries etc. in datastores. Personally, I find storing dictionaries to be the most useful because you can access values in a simple way when loading data. For example:
local fakeData = {Money = 50, Level = 5, Inventory = {"Item1", "Item2", "Item3"}}
--[[Pretend we accessed using GetAsync.
Since the function returns the data we can set the variable to the
GetAsync function and it would equal the same thing, assuming data exists]]
player.Stats.Money = fakeData.Money or 0 --[[We can access the values inside of the array
like getting objects from the workspace because we assigned each value to a "variable".
We also used the 'or 0' because the player's data table may be empty,
or their table might not have money inside of it, which would cause an error.