Game freezes when function is called