So here is the default table players start off with, which gets JSONEncoded, datastored, etc.
local data = {
Classes = {
['Knight'] = {
['ID'] = 1,
['Owned'] = true,
['Weapons'] = {
'Classic Sword',
},
['Armours'] = {
'Knight Armour'
},
['Trails'] = {
'None'
},
},
['Archer'] = {
['ID'] = 2,
['Owned'] = true,
['Weapons'] = {
'Bow and Arrow'
},
['Armours'] = {
'Archer Armour'
},
['Trails'] = {
'None'
},
},
},
ClassEquips = {
EquippedKnight = {
Weapon = 'Classic Sword',
Armour = 'Knight Armour',
Trail = 'None'
},
EquippedArcher = {
Weapon = 'Bow and Arrow',
Armour = 'Archer Armour',
Trail = 'None'
},
},
EquippedClass = 'Knight',
Level = 1,
Exp = 0,
Gold = 100,
Gems = 0
}
Then loading it in:
function dataManager:GetData(player)
local loadJSON = playerDataStore:GetAsync(player.UserId)
local data = (loadJSON and httpService:JSONDecode(loadJSON)) or data
playersData[player.UserId] = data
end
Now this is all fine for new players, but if a player loads in the for the first time, they’ll the data in the table above given to them, however, if I add more stuff to that data table, when they return they won’t have it, as it will just load in their old one. For example, adding another class:
local data = {
Classes = {
['Knight'] = {
['ID'] = 1,
['Owned'] = true,
['Weapons'] = {
'Classic Sword',
},
['Armours'] = {
'Knight Armour'
},
['Trails'] = {
'None'
},
},
['Archer'] = {
['ID'] = 2,
['Owned'] = true,
['Weapons'] = {
'Bow and Arrow'
},
['Armours'] = {
'Archer Armour'
},
['Trails'] = {
'None'
},
},
['Scout'] = {
['ID'] = 3,
['Owned'] = false,
['Weapons'] = {
'Dagger'
},
['Armours'] = {
'Scout Armour'
},
['Trails'] = {
'None'
},
},
},
ClassEquips = {
EquippedKnight = {
Weapon = 'Classic Sword',
Armour = 'Knight Armour',
Trail = 'None'
},
EquippedArcher = {
Weapon = 'Bow and Arrow',
Armour = 'Archer Armour',
Trail = 'None'
},
EquippedScout = {
Weapon = 'Dagger',
Armour = 'Scout Armour',
Trail = 'None'
},
},
EquippedClass = 'Knight',
Level = 1,
Exp = 0,
Gold = 100,
Gems = 0
}
I know I could just change the datastore to be a different name, but that would wipe out the players original data. I want when a player who already has a table saved, the game to check this table, and if there are any additions to it, add it to the players table.