How to clone a node by gdscript?

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

I’m making a zombie game and I wanted to make like a “spawn”, which spawns the zombie every 10 seconds.

:bust_in_silhouette: Reply From: Inces

Create one Zombie scene in editor and save it. It will be saved as .tscn file. So lets call it Zombie.tscn
You can access it from code by

var zombie =   preload("res://Zombie.tscn")

and create multiple clones of it by instance()for example

for x in range(10):
        var clone = zombie.instance()
        add_child(clone)