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://Player.gd”)

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() problem hereee!!!
player_instance.set_network_master(id)
player_instance.name = str(id)

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

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

_instance_player(id)

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

if has_node(str(id)):
	get_node(str(id)).queue_free()

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’. [plz help me

:bust_in_silhouette: Reply From: LeslieS

I think the problem is here:

var player = preload("res://Player.gd")

The method instance() is from a PackedScene which you get when you preload a scene.
Player.gd is a script file not a scene.
Do you not have a scene or node such as Player.tscn?

yes i have have player scene that i saved as player.tscn

ragacakaci | 2023-01-07 12:19

thank you so much i repaired it thanks to youu

ragacakaci | 2023-01-07 12:56