In foil, does it count if I hit my opponent's arm while they're attacking me?
No, a hit on the arm never scores in foil, because the arms, legs and head are off target. The foil target is the torso, front and back, from the collar down to the hip line, plus the lower part of the mask bib. A hit on the arm lights the white off-target lamp, which stops the phrase but gives nobody a point. It is different in the other weapons: in sabre the arms are valid target, and in épée the whole body is.
Right of way decides what that white light is worth. If your opponent made a correct attack, arm extending with the point threatening target, they have priority, and the referee only cares whether their hit landed on target. Their colored light beats your white one, exactly as it would beat a colored one. If their light is white or their attack missed, no touch is given and you restart about where you stopped, not back at the center lines. But if they drew their arm back, the referee may call that preparation, so your hit into it has priority, and landing on the arm stops the phrase with no touch. That is why the arm hit resets the action against a bent-arm attacker.
Hitting the arm on purpose is legal. Nothing in the rules requires you to aim at target, and the only related offense is deliberately putting your point on the floor or on anything other than your opponent to make the machine stop the action, which is a red card. Your opponent's arm is part of your opponent. If a referee threatens a card for forcing a halt, ask politely which rule they mean. A referee misreading a definite rule can be appealed to the head referee, unlike a judgment of what happened.
As a tactic, it is a stopgap, not a plan. A quick hit to the elbow or hand can break up a marching attack with a pulled-back arm without you committing deeply. But it never scores, and a good opponent will fix it by straightening the arm earlier, which gives them priority and makes your arm hit worthless. Also, once a foil registers a hit on one side, on or off target, that side cannot register again, so the arm hit ends your chance to score in that action. If you can reach their arm cleanly, ask your coach to drill parries and stop hits to the torso instead.