Data Character Counter?

So I was trying to think of how to Counter of how much Data you have in a Table, unfortunately the Data Counter is not actually a Data Character Counter but just an print statement instead

here is actually the printing:

print("Player Data is "..PlayerDataTable.." Characters")

and here is the output

 14:46:12.011 - ServerStorage.Aero.Services.StatsService:162: attempt to concatenate table with string
14:46:12.013 - Stack Begin
14:46:12.051 - Script 'ServerStorage.Aero.Services.StatsService', Line 162
14:46:12.052 - Stack End

Lastly the DataTable of the Player

local DataSample = {
    Stats = {
        Level = 0;
        Coins = 0;
        EXP = 0;
        Stamina = 0;
        Bounty = 0;
        Type = "Mage"; -- {Warrior, Mage, Tank}
    };
    
    Inventory = {
        --[[
            ["ItemName"] = {
                Path = game.ServerStorage.Objects;
                Quantity = 0;
                Type = "Item"; -- maybe sword potion etc.
                Value = 0;
            };
        ]]
    };

    Quests = {
        --[[
            ["QuestName"] = {
                ValueToFillUp = "Sample";
                ValuesReceived = 0;
                Completed = false;

                if quest is done then remove it
            }
        ]]
    };

    PreValues = {
        --[[
            -- for quests mainly
            ["ValueName"] = {
                Quantity = 0;
                IsFor = "Quest";
                MaxQuantity = 0;
            }
        ]]
    }
}

Yeah error is what it is, you are trying to print a table. I believe you are looking for this particular post on data store which tells us that we need to do some JSONEncoding first though through the example script below.

local dataS = game:GetService('HttpService'):JSONEncode(userData) --Converts data to a a string
print('You are storing '..string.len(dataS)..' characters of data') --Prints 'You are storing x characters of data'.
1 Like

cc @FerbZides

A few things to add:

  • Datastores now support up to 4MB of data per key, which is effectively 4 million characters, which is a huge amount of data PER key
  • Data in the datastore can take up slightly more space do to how values are serialized in datastores, but JSONEncode will give a good enough result that you can use string.len(dataS) < 3900000 and most likely be fine
  • If you’re storing mass amounts of data, make sure there’s no duplicate data. For example, if you have 2 identical guns store them as one with an {amount: 2} attribute.

Otherwise, you most likely will never reach the data limit anyways unless you plan on saving multiple huge player creations to the same key

2 Likes