Invalid call. Nonexistent function 'instance' in base 'GDScript'.

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

extends Spatial

var player = preload(“res://”)

func _ready():
get_tree().connect(“network_peer_connected”, self, “_player_connected”)
get_tree().connect(“network_peer_disconnected”, self, “_player_disconnected”)

Global.connect("instance_player", self, "_instance_player")

if get_tree().network_peer != null:
	Global.emit_signal("toggle_network_setup", false)

func _instance_player(id):
var player_instance = player.instance()
player_instance.set_network_master(id) = str(id)

player_instance.global_transfrom.origin = Vector3(0, 15, 0)

func _player_connected(id):
print(“Player” + str(id) + “has connected”)


func _player_disconnected(id):
print(“Player” + str(id) + “has disconnected”)

if has_node(str(id)):

what should i do? a iam making 3d sword gmae multiplayer and there is problem when i click host or join this problem shows up Invalid call. Nonexistent function ‘instance’ in base ‘GDScript’.

:bust_in_silhouette: Reply From: SteveSmith

The code

var player = preload("res://") 

needs to preload a tscn file (i.e. a scene) not a gd script. Try creating a scene called Player, add to it, and change the line to

var player = preload("res://Player.tscn") 
:bust_in_silhouette: Reply From: godot_dev_

If you want to instance a script (as opposed to a scene), you would need to do it as follows:

var playerNode =

This assumes your player scene is of type Node. If it’s not, then you want to use a scene instead of a script. But in your case, since your using player_instance.global_transfrom.origin = Vector3(0, 15, 0), it implies the player instance is not of type Node, so you probably want to instance the scene like @SteveSmith suggested