$NodeName is just a macro for
get_node("NodeName"), so in your example your
$chestnode/AnimatedSprite.play("open") line is the same as doing
get_node("chestnode/AnimatedSprite").play("open") which is probably why it's return a null reference, there's no node literally called "chestnode".
Once you've made a reference to a node (either through
get_node() or the
$ macro), you do not need to retrieve the node again to call functions on it. You can just use
node_reference.function_call(). In your example, you're specifically wanting to get a child node of
chestnode, so there are a few ways of achieving this.
You can either use string concatenation in the first
get_node() call like this:
get_node(chestname + "/AnimatedSprite").play("open")
You could also use the existing
chestnode reference and make another
get_node() call. It's important to note that you can't use the macro (
$) in this case because the macro takes everything after it as a literal string, rather than looking at any variables.
Personally, I would recommend the first in your current example, but switch to the second one if you end up doing multiple things with the