Why does my array give me this error?

Godot Version

4.3

Question

I don’t understand the reason of why this error comes up:
Invalid assignment of index '0' (on base: 'Array[StringName]') with value of type 'StringName'.
This is the code:

extends Node

var human:PackedScene = preload("res://scenes/human.tscn")
@export var villagers = 100
var humanInstance:CharacterBody2D
var humanArray:Array[StringName]

func _ready() -> void:
	for x in villagers:
		humanInstance = human.instantiate()
		get_node("humans").add_child(humanInstance)
		var path:String = "humans/"+humanInstance.name
		humanArray[x] = get_node(path).name
		print(humanArray[x])

This is the whole tree, even though I don’t think this is related to my problem:
image

Any help is appreciated, thanks in advance.

It will:

humanArray.append(get_node(path).name)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.