As evidenced in the comments and David´s answer, the problem is that even if each $A_n$ is closed, there can be too much "interaction" between the $A_n$'s. A more extreme example would be to take $A_n=\{ q_n \}$ where $\{q_n\}_{n=1}^\infty$ is some enumeration of the rational numbers.

However if $\{A_n \}_{n=1}^\infty$ is a discrete family of closed subsets of the normal space $X$ and $\{c_n \}_{n=1}^\infty$ is any sequence of real numbers, then there is a continuous $f:X \to \mathbb{R}$ such that $f$ takes the constant value $c_n$ in each $A_n$. For this just note that the union of the $A_n$´s is closed in $X$ and each $A_n$ is clopen in this union.

**Note:** a family $\{A_n \}_{n=1}^\infty$ of subsets of the space $X$ is a *discrete family* if any $x \in X$ has a neighborhood that intersects at most one of the $A_n$'s.