Constantly losing specific data

So basically I’ve been dealing with this issue of my datastore. I’ve received reports of losing max XP and xp mostly. Not sure why those two stats specifically are being lost. I am yet to receive a report of losing other stats. Here is my script:

local DataStore2 = game:GetService("DataStoreService"):GetDataStore("V5")

game.Players.PlayerAdded:Connect(function(player) 

	local moreStats = Instance.new("Folder", player)
	moreStats.Name = "leaderstats"
	local hide = Instance.new("Folder", player)
	hide.Name = "stats"


	local Lvl = Instance.new("IntValue", moreStats) --Level stat
	Lvl.Name = "Level"
	Lvl.Value = 1


	local cash = Instance.new("IntValue", moreStats)
	cash.Name = "Cash"
	cash.Value = 200
	
	local rank = Instance.new("StringValue", moreStats)
	rank.Name = "Rank"
	rank.Value = "Private"
	
	local kill = Instance.new("IntValue", moreStats)
	kill.Name = "Kills"
	kill.Value = 0
	
	local XP = Instance.new("IntValue", moreStats) --XP stat
	XP.Name = "XP"
	local maxXP = Instance.new("IntValue", moreStats) --MaxXP stat
	maxXP.Name = "Max"
	maxXP.Value = 100
	

	XP.Changed:Connect(function(val)
		if XP.Value >= maxXP.Value then
			Lvl.Value = Lvl.Value + 1
			XP.Value = 0
			maxXP.Value = maxXP.Value + 100 -- Increases MaxXP per level.
		end
	end)
	
	Lvl.Changed:Connect(function(val)
		if Lvl.Value >= 1 then
			rank.Value = "Private"
		end
		if Lvl.Value >= 5 then
			rank.Value = "Bronze I"
		end
		if Lvl.Value >= 15 then
			rank.Value = "Bronze II"
		end
		if Lvl.Value >= 20 then
			rank.Value = "Bronze III"
		end
		if Lvl.Value >= 30 then
			rank.Value = "Silver I"
		end
		if Lvl.Value >= 50 then
			rank.Value = "Silver II"
		end
		if Lvl.Value >= 60 then
			rank.Value = "Silver III"
		end
		if Lvl.Value >= 75 then
			rank.Value = "Elite"
		end
		if Lvl.Value >= 85 then
			rank.Value = "Silver Elite"
		end
		if Lvl.Value >= 100 then
			rank.Value = "Master Elite"
		end
		if Lvl.Value >= 125 then
			rank.Value = "Guardian"
		end
		if Lvl.Value >= 150 then
			rank.Value = "Uber I"
		end
		if Lvl.Value >= 175 then
			rank.Value = "Uber II"
		end
		if Lvl.Value >= 200 then
			rank.Value = "Uber Master"
		end
		if Lvl.Value >= 225 then
			rank.Value = "Relic"
		end
		if Lvl.Value >= 250 then
			rank.Value = "Resplendent"
		end
		if Lvl.Value >= 275 then
			rank.Value = "Radiant"
		end
		if Lvl.Value >= 300 then
			rank.Value = "Stellar"
		end
		if Lvl.Value >= 350 then
			rank.Value = "Vanguardian"
		end
		if Lvl.Value >= 400 then
			rank.Value = "Crystalline"
		end
		if Lvl.Value >= 420 then
			rank.Value = "Totally Accurate Warrior"
		end
		if Lvl.Value >= 450 then
			rank.Value = "Totally Accurate Guardian"
		end
		if Lvl.Value >= 500 then
			rank.Value = "Emund's Disciple"
		end
	end)
	


	local LvlData
	local XPData
	local maxXPData
	local rankdata
	local cashdata
	local killdata

	pcall(function()
		LvlData = DataStore2:GetAsync(player.UserId.."-Lvl")
		XPData = DataStore2:GetAsync(player.UserId.."-XP")	
		maxXPData = DataStore2:GetAsync(player.UserId.."-maxXP")	
		rankdata = DataStore2:GetAsync(player.UserId.."-rank")
		cashdata = DataStore2:GetAsync(player.UserId.."-cash")
		killdata = DataStore2:GetAsync(player.UserId.."-kill")
		print('gotten data')
	end)	

	if LvlData ~= nil then
		Lvl.Value = LvlData
		print('transferred data')
	end

	if XPData ~= nil then
		XP.Value = XPData
	end

	if maxXPData ~= nil then
		maxXP.Value = maxXPData
	end
	
	if cashdata ~= nil then
		cash.Value = cashdata
	end
	
	if killdata ~= nil then
		kill.Value = killdata
	end
end)
game.Players.PlayerRemoving:Connect(function(player)

	DataStore2:SetAsync(player.UserId.."-Lvl",player.leaderstats.Level.Value)
	DataStore2:SetAsync(player.UserId.."-XP",player.leaderstats.XP.Value)
	DataStore2:SetAsync(player.UserId.."-maxXP",player.leaderstats.Max.Value)
	DataStore2:SetAsync(player.UserId.."-rank",player.leaderstats.Rank.Value)
	DataStore2:SetAsync(player.UserId.."-cash", player.leaderstats.Cash.Value)
	DataStore2:SetAsync(player.UserId.."-kill",player.leaderstats.Kills.Value)

end)

game:BindToClose(function()
	wait(10)
end)

I can’t really understand what I’ve done wrong, please help out if you can.

I would make use of tables instead of saving each value individually which should help. If you don’t want to do that I would recommend creating a SaveData function and having that run when the player leaves and is in the bind to close, that should help. Auto-saving could also be helpful but may cause more problems if done too frequently.