How do I add back a removed async?

So I had this code which would RemoveAsync your data because I thought it would just wipe your data and when you joined back it would give you default data. However, people who got wiped don’t have anything like at all not even default data, they just can’t have data and whenever they join it’s nil instead of loading in default data. This is my code, how can I change it to like make it so they can actually have data again:

local function loadData(player)
	print(player)
	local success = nil
	local playerData = nil
	local attempt = 1

	repeat
		success, playerData = pcall(function()
			return dataBase:GetAsync(player.UserId)
		end)

		attempt += 1
		if not success then
			warn(playerData)
			task.wait()
		end
	until success or attempt == 3

	if success then
		
		if not playerData then--give default data if they're new
			playerData = {
				["Gems"] = 0,
				["SelectedTowers"] = {"Cameraguy"},
				["OwnedTowers"] = {"Cameraguy"},
				["MaxTowers"] = 5,
				["RedeemedCodes"] = {}
			}
		end
		
		data[player.UserId] = playerData

Any help is appreciated, thanks!

That was kinda worded weirdly, basically, someones data got RemoveAsync’d and now their data is just permanently nil no matter how many times they rejoin, it won’t even give them default data, it’s just nothing

If you don’t have earlier versions of the datastore then you really can’t get back that data.

Dang, if I can’t do that, how can I make it so they atleast get a default players data and can move on from there

Set their data on join or manually I guess. There’s no default value for a datastore other than nil.

No I mean here:

if not playerData then--give default data if they're new
			playerData = {
				["Gems"] = 0,
				["SelectedTowers"] = {"Cameraguy"},
				["OwnedTowers"] = {"Cameraguy"},
				["MaxTowers"] = 5,
				["RedeemedCodes"] = {}
			}

How can I give them that default data because the script wont even load that for them

Sorry, I didn’t read your post correctly.

Did you actually save data[player.UserId] when the player disconnects?

Yeah, here:

--save player data
local function saveData(player)
	print(player)
	if data[player.UserId] and player.UserId ~= 0 then
		local success = nil
		local playerData = nil
		local attempt = 1

		repeat
			success, playerData = pcall(function()
				return dataBase:UpdateAsync(player.UserId, function()
					return data[player.UserId]
				end)
			end)

			attempt += 1
			if not success then
				warn(playerData)
				task.wait()
			end
		until success or attempt == 3

		if success then
			print("Data saved successfully")
		else
			warn("Unable to save data for player", player.UserId)
		end
	else
		warn("No session data for", player.UserId)
	end
end
Players.PlayerRemoving:Connect(function(player)
	saveData(player)
	data[player.UserId] = nil
end)

game:BindToClose(function()--if game shuts down
	if not RunService:IsStudio() then
		print("Shutting down")
		for index, player in pairs(Players:GetPlayers()) do
			task.spawn(function()
				saveData(player)
			end)
		end
	else
		print("Shutting down inside studio")
	end
end)

From what I’ve heard, Studio would fail to save sometimes when the test instance closes earlier than PlayerRemoving can finish executing, so data wouldn’t save.

Can you double-check on this?