How do I measure how much space a specific value in a datastore is taking up?
i guess there is plugin for datastore not sure if that can help
The question is how, if there is a plugin that does it I want to know how it works.
Create or get a module with the information and export it, DataStore Editor can do it for you.
Next, open the file settings and see how much it weighs:
Module: return 10
File:
Here’s something bigger:
Module
return {
"Sword",
"Apple",
"Cookie",
"Taco"
}
File:
That works, but I don’t want to have to download a .lua file everytime. Is there any easy way I can just make a function and insert a value and it will output the data size, potentially with HttpService?
With this function:
local Data = game:GetService("DataStoreService"):GetDataStore("Inventory")
local suc,dat = pcall(function()
return Data:GetAsnyc("Sword")
end)
print(game:GetService("HttpService"):JSONEncode(dat):len())
Original post:
It does not give exact, but it works.
The above post gives some code that works but I will go into more detail here.
Datastores encode the what you put in into JSON. So, to get the size of a value in a datastore, just encode it into JSON using HttpService:JSONEncode then get the length of the string.
How accurate is that though? because in the post provided
not each character is exactly 1 byte
It is accurate as string.len returns the number of bytes, not the number of unicode characters. If you do string.len on a unicode character you will see it returns 2 or more.
Can you provide an example of string.len returning a different number than the characters? Because for me it’s returning the same.
Try doing string.len on an emoji or some other unique character. I’m on mobile so I can’t test right now but something like this should work:
print(string.len("😔"))
Eh… You’re welcome! Happy to help xd
I still say that it is not exact because it is the size of the string, but not in bytes as it is saved by roblox
Yeah I noticed a little discrepancy between the file, it should be fine though for what I am trying to do.
string.len returns LENGTH of string, not how much data it is taking
It will be same as #“”
(Sorry for reviving, but it is kind of disinformation you give)