How do I change player data that is already set?

I’m using profile service as my data module and I can’t figure out how to add a new category of data to all players who already have data.

For example this is what my current save template looks like:

local SaveTemplate = {
    
    Cash = 0;
    Wins = 0;
    Kills = 0;
    
    Inventory = {
        
        Knives = {"Default"};
        KillAnimations = {"Default"};
        Radios = {}

    };

    Gamepasses = {

        VIP = false;
        Radio = false;

    }
    
}

This save template is only given to new players with no data, so if I added a new category to my save template it wouldn’t be added to players with existing data.

How can I give data to all players?

If you mean everyone that joined your game, you would need to store every player’s userid that joined the game, then update their data using their userid.

If you mean adding a new “category” to every player that joins the game, that should work fine as their default value would be whatever you set it to, then saved later on.

As long as you keep it within the SaveTemplate, anything containing it should save as well.

ProfileService automatically gives them the new data I’m pretty sure. Have you tested it yourself?

Yeah, I tried adding a new knife to the save template but it didn’t work because I already had data.

I’ll double check this, last time I added a new category it wouldn’t be implemented within players with existing data.

What are you using (DataStore2, ProfileService / any other custom DataStore scripts?)

I’m just using ProfileService.

I double-checked to see if it would work by writing a script that prints the categories stored in my players save template after adding a new category called “TestTable”

local SaveStructure = {
    
    Cash = 100;
    Wins = 0;
    Kills = 0;
    
    Inventory = {
        
        Knives = {"Default"};
        KillAnimations = {"Default"};
        Radios = {}

    };

    Gamepasses = {

        VIP = false;
        Radio = false;

    };

    TestTable = {

        Test = true
    }
    
}

It didn’t add the category to my player because I already had saved data, I’m not sure how I can get around this because eventually, I’ll need to make new categories and add new default data for all players to have.

In that case, you would need to check if they have the category, if not: insert it to players who already has their old data saved.

if not Table.CATEGORY_NAME then

Then use table.insert() to add it to their categories.

That should work, I will keep searching for a other ways to get this same result. I wonder how big game do this.

Probably the same way, because once you add something new, the players who already has the old data stored needs the updated values.

I think bigger games plan this up-front and add the features later, just like they were there from the start then changed in the future for players to use.

1 Like