Show the iff statement of lower semicontinuous

Let's begin with the "if" part: I'm gonna show that if $y_n\rightarrow y$ then $f(y)\leq\liminf f(y_n)$. Let $\epsilon_n=\frac{1}{n}$; by hypothesis, for each $n$ we can find some $\delta_n$ such that $f(y)\leq f(y_n)+\epsilon_n$. Now you take the inferior limit.

To finish, take a sequence $(y_n)\subset f^{-1}((-\infty,r])$ such that $y_n\rightarrow y$. By using what we have just proved, we have that $f(y)\leq\liminf f(y_n)$. Can you conclude?

On the other and, suppose that for all $r$, the set $f^{-1}((-\infty,r])$ is closed and suppose ad absurdum that there exist $\epsilon>0$ such that for all $\delta_n=\frac{1}{n}$, we can find $y_n\in B(\delta_n,x)$ with $$f(y)>f(y_n)+\epsilon$$

The last inequality implies that $y_n\in f^{-1}((-\infty,f(y)-\epsilon])$. Can you use the fact that $f^{-1}((-\infty,r])$ is closed and $y_n\rightarrow y$ to conclude?

Note: The hypothesis of $X$ being closed is unnecessary.