Loading is asynchronous - ie. you can’t use model until it is there. It should be enough if you created an external variable and assigned model to it. Then in the render loop, check if the variable is already defined - if it is, do the animating. (See this for example.)
Alternatively you can give your model a name using: