local function y(y,Z)local s=main.pd[y]if s and(s.DataToUpdate or Z)then return(main:GetModule("\068\097\116\097\083\116\111\114\101\115")):DataStoreRetry(datastoreRetries,function()return playerDataStore:UpdateAsync(y.UserId,function(Z)local A=Z or{DataKey=0}if s and main.pd[y]then if s.DataKey==A.DataKey then main.pd[y].DataToUpdate=false main.pd[y].DataKey=s.DataKey+1 local Z={}for y,s in pairs(main.pd[y])do Z[y]=s end if not Z.SaveRank then Z.Rank=0 end local M=dataNotToSave()for y,s in pairs(M)do Z[s]=nil end A=Z else A=nil end end return A end)end)end end
--Save data to DataStore
local function savePlayerData(player, playerLeaving)
	local pdata = main.pd[player]
	if pdata and (pdata.DataToUpdate or playerLeaving) then
		return main:GetModule("DataStores"):DataStoreRetry(datastoreRetries, function()
			return playerDataStore:UpdateAsync(player.UserId, function(oldValue)
				local newValue = oldValue or { DataKey = 0 }
				if pdata and main.pd[player] then
					if pdata.DataKey == newValue.DataKey then
						main.pd[player].DataToUpdate = false
						main.pd[player].DataKey = pdata.DataKey + 1
						--
						local pdataToSave = {}
						for a, b in pairs(main.pd[player]) do
							pdataToSave[a] = b
						end
						if not pdataToSave.SaveRank then
							--if playerLeaving and not pdataToSave.SaveRank then
							pdataToSave.Rank = 0
						end
						local dataNotToSave = dataNotToSave()
						for i, v in pairs(dataNotToSave) do
							pdataToSave[v] = nil
						end
						--
						newValue = pdataToSave
					else
						newValue = nil --Prevent data being overwritten
					end
				end
				return newValue
			end)
		end)
	end
end
