IntValue being set to 0 upon leaving

I want to save a folder, but the values of the IntValues keeps getting set to 0 upon leaving. I know it’s 1 before the player leaves.
Any idea how i can fix this?

game.Players.PlayerRemoving:Connect(function(plr)
	local s, e = pcall(function()
		local count = 0
		datastore:SetAsync(plr.UserId..'-cash', plr.leaderstats.Cash.Value)
		datastore:SetAsync(plr.UserId..'-max', plr.stats.max.Value)
		while count < 16 do
			wait(0.1)
			count+=1
			if plr.merged:FindFirstChild(count) then
				print(plr.merged[count].Value)
				datastore:SetAsync(plr.UserId..'-slot'..count, plr.merged[count].Value)
			end
		end
	end)
	if not s then print("bruh") 
	end
end)
game:BindToClose(function()
	wait(3)
end) 

If you are testing this in studio you need to save the value in the BindToClose function as this is what triggers when you leave the server in studio.

I am, but it doesn’t work outside of studio either.