The new() on this line:
@onready var bot_script = preload("res://Scripts/BotState.gd").new()
creates an instance of the BotState script; that is an object and not a script.
This line:
var new_bot_script = bot_script.duplicate()
simply creates a duplicate instance of the object (again not a script).
This line:
bot_node.set_script(new_bot_script)
I am surprised isn't erroring out on you.
Remove the new()
from the variable definition line and remove new_bot_script
and just
bot_node.set_script(bot_script)
bot_node.key = node + 1
However, it is my opinion that the approach here is awkward.
I recommend creating a single bot node with attached script and then where and when you need a bot, create new instances of it. Those will come with their script already attached.