UpdateAsync issue

My datastore wont save and i dont know why. There’s no errors either.

Code:

local player = game:GetService("Players")
local dss = game:GetService("DataStoreService")
local DataStore = dss:GetDataStore("MimiSaveSytem")

player.PlayerAdded:Connect(function(plr)

	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = plr

	local stage = Instance.new("IntValue")
	stage.Name = "Wins"
	stage.Parent = stats
	
	local data = DataStore:GetAsync(plr.UserId)
	if data then
		print(data.Wins)
		for _,stat in pairs(stats:GetChildren()) do
			stat.Value = data[stat.Name]
		end
	else
		print(plr.Name .. " has no data")
	end
end)

local function savePlrData(plr)
	local success,err = pcall(function()
		DataStore:UpdateAsync(plr.UserId, function(currentVal)
			return currentVal
		end)
	end)
	if not success then return err end
end

player.PlayerRemoving:Connect(function(plr)
	savePlrData(plr)
end)

game:BindToClose(function()
	for _,plr in pairs(player:GetPlayers()) do
		savePlrData(plr)
	end
end)
Here are the solutions i tried:
  1. (code that i took from my now deleted topic which doesn’t work correctly anymore too)
local function savePlrData(plr)
	local success,err = pcall(function()
		DataStore:UpdateAsync(plr.UserId, function()
			local saveData = {}
			for i, data in pairs(plr.leaderstats:GetChildren()) do
				saveData[data.name] = data.Value
			end
			DataStore:UpdateAsync(plr.UserId, saveData)
		end)
	end)
	if not success then return err end
end
  1. idk why i did this-
local function savePlrData(plr)
	local success,err = pcall(function()
		DataStore:UpdateAsync(plr.UserId, function(currentVal)
			return newval
		end)
	end)
	if not success then return err end
end

I think it dont save anything because UpdateAsync is to update an already created async. To create it use SetAsync.

Use this one but change this line

to

return saveData

You should add this line of code to else to prevent this happening, why this happens is you try to get a datastore that does not exist so you need to make it exist if it does not exist using :SetAsync().

Add this to else:
Datastore:SetAsync(plr.UserId,0)

thanks. i should’ve done that in the morning instead. now excuse me. im gonna cringe and cry because of myself