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.
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?
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)
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:
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.")
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 ( !
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))
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.
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.