You defined the variable enemy twice, once as a member variable and once as a variable in a method. That’ll throw an error for redefining a variable. My convention is to call the add scene onto the name of the scene as below.
You had a Vector3 with only 2 components (I just put zero in the third, you might want to change that)
I randomized the seed for you so it’s not the same every time.
I changed the member variable to a preload - not an error as such, it’s just a better approach imo.
That’s all I think unless I missed anything.
extends Spatial
onready var main = get_tree().current_scene
var enemy_scene = preload("res://enemy.gd")
func spawn():
randomize()
var enemy = enemy_scene.instance()
main.add_child(enemy)
enemy.transform.origin = transform.origin + Vector3(rand_range(-15, 15), rand_range(-10, 10), 0)
func _on_Timer_timeout():
spawn()