Issue with datastore key save limit

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

image

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:

image

any help will be appreciated

Hello! I’ve attached a great post explaining how datastore limits work.

1 Like

thanks ill look into that

char limit

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.

1 Like

so i did the decode like this:

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

You don’t decode the data coming from the data store. You just need to encode your table and get the length of the string

local Http = game:GetService("HttpService")
				
local SavedData = FurnitureLocationsDS:GetAsync(plr.UserId)

print(string.len(Http:JSONEncode(SavedData)))
1 Like

it prints 741 thats bytes right?
so that means its 0.000741 megabytes

and thats for 1 furniture, i think im fine and it will take a long time before the datastore reaches its limit

Yea that number is in bytes. Each character of the JSON string will be a byte.

1 Like

appreciate the help !

character limit

1 Like

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.

For example

local x = "😊"
print(x:len()) -- prints 4

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.