Updating Dictionaries when saved to datastore already

You can run through the player’s data and check for inconsistencies based on a template. Here’s an example:

local defaultSkills = {
	Ice = {Skill1 = 'Freeze', Skill1Owned = false,
		Skill2 = 'Ice Breath', Skill2Owned = false}
}

function CheckConsistency(sample, template)
	for a, b in pairs(template) do
		if sample[a] == nil then
			sample[a] = template[a]
		end
		if type(b) == 'table' then -- loop through any nested tables as well. In this case, 'Ice' is a nested table
			CheckConsistency(sample[a], template[a])
		end
	end
	return sample
end

local updatedInfo = CheckConsistency(YourDataHere, defaultSkills)
4 Likes