Data Store Change / Drop Issue

Hello people of this kingdom! I saw many posts about people who want to drop (delete) their data stores, but since it’s not possible, here’s a workaround that I do in order to change their data to the newest version.
Let’s say I hava a data like:

local defaultData = {
	Version = "Alpha",
	Money = 0,
	Wins = 0,
}

Now pay attention that I also have a “Version” key, so now we can do:

local DATA = game:GetService("DataStoreService")
local CurrentVersion = "Beta"

local function defaultData() ... end

local function loadData(player: Player)
	local data = dataStore:GetAsync(player.UserId)

	if data.Version ~= CurrentVersion then return defaultData() end
	return data or defaultData()
end

This overrides the old data to the current version’s default data, but if you want to keep some old data you can do:

local function loadData(player: Player)
	local data = dataStore:GetAsync(player.UserId)

	if data.Version ~= CurrentVersion then
		local updateData = defaultData()
		updateData.Money = data.Money
		return updateData
	end
	return data or defaultData()
end

Now I’m on my phone, so I hope I typed everything correctly.
Also, notice that defaultData() is a function, so it always returns a table, but if you’d get directly the default data table, you’d need to table.copy() it, and if it’s deeper then you must make a deepClone function. However, for me it’s easier to just return the default data table (hope you understood this part)

Also. don’t forget to use pcall() or use another safety function to retrieve the data.
Thanks gang :fire: