I assume $X$ is a metric space. Suppose it is not compact. Then there is a sequence $x_n$ that has no convergent subsequence. Moreover, since $X$ has only finitely many isolated points, after removing a finite number of points we can assume none of the $x_n$ are isolated. We may also assume the $x_n$ are distinct. For each $n$ there is $\epsilon_n$ such that $1/n > \epsilon_n > 0$ and $d(x_m, x_n) > \epsilon_n + \epsilon_m$ for all $m \ne n$. Since $x_n$ is not isolated, we can assume there is $y_n \in X$ such that $\epsilon_n = d(x_n, y_n)$. Consider the function $f(x) = \sum_n f_n(x)$ where $f_n(x) = \max(0, 1 - d(x, x_n)/\epsilon_n)$, and show that this satisfies the conditions.