This problem is from a Ph.D Qualifying Exam on Probability Theory.
Suppose that $\{X_n:n\geq 1\}$ are random variables on a probability space $(\Omega,\mathcal{B},\mathbf{P})$ and define $S_n:=\sum_{i=1}^nX_i,n\geq 1$. Let $\tau:=\inf\{n>0:S_n>0\}$ and assume that $\tau<\infty$ almost surely. Prove that $S_\tau$ defined as $S_\tau(\omega)=S_{\tau(\omega)}(\omega)$ is a random variable.
My attempt: I already proved that $\tau$ is a random variable. Then I'm struggling to prove that for any real number $a$, $\{S_\tau >a\}$ is an event. Since the number of summands for $S_\tau$, namely $\tau(\omega)$, varies by $\omega$, I can't claim that $S_\tau$ is a sum of random variables. Is there any other way to prove the measurability of $S_\tau$?
Thanks in advance!
Hint $$\{S_{\tau}>a\} = \bigcup_{n \in \mathbb{N}} \{S_n > a\} \cap \{\tau=n\}.$$