How to make instances unique? changing animationPlayer affects every instantiated node

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By light404

Hi, I wanter to create a character that looks different from one another, so I made a spritesheet of “heads”. The code below selects an index randomly, and then sets the sprite key-frame into the animation.

This is working well, except that it changes for all the characters…
This is what it looks like:
Reddit Post - with GIF

const HEAD_VARIATIONS = 2
const FRAMES_PER_HEAD_VARIATION = 4
onready var mainAnimPlayer = $MainAnimationPlayer
 
func _setup_head_sprite():
    randomize()
    var ri = randi()
    var fIndex = (ri % HEAD_VARIATIONS) * FRAMES_PER_HEAD_VARIATION
    print('fIndex:', fIndex)
    
    var wdown = mainAnimPlayer.get_animation("WalkDown")
    wdown.track_set_path(1, "HeadSprite:frame")
    wdown.track_insert_key(1, 0.0, fIndex)
    
    var wright = mainAnimPlayer.get_animation("WalkRight")
    wright.track_set_path(1, "HeadSprite:frame")
    wright.track_insert_key(1, 0.0, fIndex + 1)
    
    var wup = mainAnimPlayer.get_animation("WalkUp")
    wup.track_set_path(1, "HeadSprite:frame")
    wup.track_insert_key(1, 0.0, fIndex + 2)
    
    var wleft = mainAnimPlayer.get_animation("WalkLeft")
    wleft.track_set_path(1, "HeadSprite:frame")
    wleft.track_insert_key(1, 0.0, fIndex + 3)

Thanks in advance!