the issue that i just realised recently is that the way i datastore furniture locations in my building system is by putting all data in a table like this:
but what ive seen is that the limit per key is 4mb so how much does this take? (this is for each furniture, and the way i made the datastore is by making a parent table that has all apartments like this
and each apartment has a table that contains all the furnitures, but im worried that this takes a lot of space and the key will reach its limit, how can i stop this from happening?
and how can i make a meter for the amount of data the player is using like in bloxburg:
If you want to know the size of the data, you can call HttpService.JSONEncode on your table and then get the length of the returning string. Roblox does this internally before it saves your table to the datastore.
local Http = game:GetService("HttpService")
local DecodedData = Http:JSONDecode(FurnitureLocationsDS:GetAsync(plr.UserId))
print(string.len(Http:JSONEncode(DecodedData)))
but it prints 2
idk what 2 means is it megabytes or bytes
Edit: i think its broken because ive tried the same print with different datastores and it all prints 2 for some reason
It should be noted that this is only true for characters that are available in ASCII, other Unicode characters will take a different number of bytes each. This is due to the UTF-8 encoding that strings in datastores use. (Iâm not sure if luau strings in general use UTF-8 encoding but datastore strings do)
Just about any character youâd use in normal English language or programming is available in ASCII but characters from other languages and emoji will use more that 1 byte per character.
As far as I know, Lua treats all strings as simple byte sequences and doesnât necessarily have a concept of âcharactersâ or encodings. I could be wrong though. So string.len prints the number of bytes in the string and not necessarily the number of characters.