Is this how you would calculate how much data is being used?

  1. What do you want to achieve? Keep it simple and clear!

So i got a datastore for my game which stores a models info as a dictionary.

  1. What is the issue? Include screenshots / videos if possible!

My issue is that i suck at math. Literally… And i want to be able to show the player how much data theyre using?

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I actually did some research and found that you could use “JSONEncode()” to check data length.
But i basically got stuck there. So I tried some math stuff and came up with this. Though im not sure if this is how i would count how much data is being used?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Cant inlcude any screenshots since Roblox is down. So sorry if i get something wrong here

Value.Changed:Connect(function(VAL) -- // Value counts when a object is being added/removed from a folder
script.Parent.Text = VAL / 4000000 
end)
1 Like

The maximum length of any value associated with a given key for any particular DataStore is 4 million characters. You could divide the character length of a value by 4,000,000 and then multiply the result by 100 to get a percentage of potential data used. For example if some key of any given DataStore has an associated value which is exactly 4,000 characters in length:

(4,000 / 4,000,000) * 100 = 0.1%

1 Like

Alright. I’ll make sure to try this out when roblox is back up!

local DataStore = game:GetService("DataStoreService")
local Data = DataStore:GetDataStore("DataStore")

local DataStoreValue = Data:GetAsync("") --some key
local DataUsed = DataStoreValue / 40000 --4 million multiplied by 100
print("You have used ", DataUsed, "% of your save file.")
2 Likes

I’ll mark this as solved for now so people doesnt get confused. I belive your solution works since it seems like you know what youre talking about. Thanks for the help (:slight_smile: !

1 Like

That won’t work, you have to JSONEncode the data then get the length of it.

local httpService = game:GetService('HttpService')

local dataStoreService = game:GetService('DataStoreService')
local dataStore = dataStoreService:GetDataStore('SomeDataStore')

local encodedData = httpService:JSONEncode(dataStore:GetAsync('SomeKey'))
local used = (encodedData:len() / 4000000) * 100
print(string.format('%u%% of data is being used', used))
6 Likes

Mine would work, it largely depends on the type of data being stored.

1 Like

if i want to use this what do i put in the (“some key”) part

Some key which belongs to the DataStore, largely depends on how you’re storing values. I’m assuming userID?

yes I think im storing leader stats with userid

If it’s just userID then :GetAsync(“userid”) is all you need. The key should be a string.

1 Like

No it won’t. Unless the data is being saved as a number, you can’t divide it by 4,000,000. And even then it will be inaccurate because it’s doing the arithmetic on the value, not the length.

@natty_boppin, you likely have your load function connected to a PlayerAdded event, something like this should work:

local players = game:GetService('Players')

players.PlayerAdded:Connect(function(player)
    local encodedData = httpService:JSONEncode(dataStore:GetAsync(player.UserId))
end)

Although I advise against getting the player’s data every time you want to see how much data they’re taking up. You should compile their data as if it were ready to be saved, and then encode it, then get the length.

2 Likes

Yes you can, the calculation is just getting the length of a string using len() or # and then dividing that value by 4,000,000 and then multiplying by 100. Did you really think this whole time the value itself was being divided by 4,000,000? Not to mention this thread has already been marked as solved.

I belive your solution works since it seems like you know what youre talking about.

he said he believes it works so it might not work

I think i should back on here. I completley forgot i made this post.

Yes limited_unique’s solution worked perfectly. No need to keep posting here(:slight_smile: