Let $(X,d)$ be a connected metric space and $f:X \rightarrow \mathbb{R}$ be a continuous function. Suppose that for every $x \in X$ there exists an open set $U \subseteq X$ so that $x \in U$ and ${f|}_n:U \rightarrow \mathbb{R}$ is constant. Prove that $f:X \rightarrow \mathbb{R}$ is constant.
I don't know where to start with this problem