I have seen pictures of Civil War muskets with notches, either in the stock or on the barrel. They are far too even to be unintentional scratches or damage. That said, no one is really certain that they are kill marks. It could just be that the soldier was bored and decided to whack some notches into his musket stock.
Soldiers in other wars occasionally notched the stocks of their rifles, but doing so was rare. The rifle did not belong to the soldier, and any “personalizing” like carving initials, kill marks, or any sort of marking on the rifle was against regulations and the soldier could get in big trouble for it. That said, I have heard of many rifles with notches on them, but again, most are not confirmed to be kill marks.
T.E. Lawrence, aka Lawrence of Arabia, received a captured Lee-Enfield rifle, which he then used during the Arab revolt. He carved his initials and the presentation date into the stock, and also carved five notches into the stock to mark the number of kills he had with it. The rifle is now in display in the Australian War Museum.
Sergeant Frank Kwiatek supposedly cut notches into his rifle in WWII. He had vowed to kill 25 Germans after his brother had been killed. According to one account, he was carving the 22nd notch into his rifle after the battle of Normandy. I don’t know if he ever got to 25 or not.
I also know of other ways that soldiers marked their kills. One kept the brass casing from any bullet that killed someone. At first he put them in his helmet band, but when someone else figured out what he was doing and chewed him out for it he switched to keeping the shell casings in his pocket.
Semen Nomokonov, a Soviet sniper from Sibera in WWII, put notches on his smoking pipe to mark his kills.
It should be noted that other than the Civil War rifles, the rest of these were long after the cowboy/gunslinger trope had been established.
Tanks too, by the way. Most were marked with lines or rings on the barrel, but some had marks on the turret instead.
And also apparently the occasional anti-aircraft gun as well: