Notation(from Kunnen): $M$ is countable transitive model of $ZFC$, $P$ is a partial order that belongs to $M$, $G$ is a $P$-generic filter over $M$, $\hat{b}$ will be a $P$-name for $b\in M$, and $M[G]$ is the smallest model of $ZFC$ containing $G$ and $M$.
The exercise i'm trying to do is the following: If $f$ is a function with range contained in $M$ and $f$ belongs to $M[G]$ then there is a set $B$ that belongs to $M$ containing the range of $f$. The hint given is to consider
$B=\left \{ b:\exists p \in P(p\Vdash \hat{b} \in \operatorname{Rng}(\tau ) ) \right \} $ where $\operatorname{val} (\tau,G) = f$
I understand that this describes the desired $B$ as a class in $M$ but i can't find a way to show that this is actually a set in $M$.
Thanks for the help and sorry for the trivial question.
Here is a quick proof, which doesn't use the hint.
If $f$ is a function in $M[G]$ with $\text{ran}(f)\subset M$, then since $\text{ran}(f)$ is a set in $M[G]$, it has some von Neumann rank $\alpha$ there. Thus, every element of $\text{ran}(f)$ has rank less than $\alpha$. Since rank is absolute and $\alpha$ is an ordinal in $M$, it follows that $\text{ran}(f)\subset (V_\alpha)^M$, and this is a set in $M$.
(This proof requires you already to know that $M$ and $M[G]$ have the same ordinals and that $M[G]$ satisfies ZFC.)