Player stops for 1 sec before next level

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

I want to add a function where when the Player is pressed that the Player stops for 1 sec and it doesn’t add any scores, like it freezes totally for 1 sec.

This is my Main script

onready var Player1 = preload("res://Player/Player1.tscn")

func _on_player1_pressed():
	Player1.stop()
	yield(get_tree().create_timer(1.0), "timeout")
	get_tree().change_scene("res://Game.tscn")

error: Invalid call. Nonexistent function ‘stop’ in base ‘PackedScene’.

So i tried to use a signal

onready var Player1 = preload("res://Player/Player1.tscn")

func _on_player1_pressed():
	emit_signal("next_level")
	yield(get_tree().create_timer(1.0), "timeout")
	get_tree().change_scene("res://Game.tscn")

Player script

func _process(delta: float) -> void:
	player_sprite.connect("next_level", self, "_on_next_level")

func _on_next_level():
	player_sprite.stop()

but stop() functions gives always an error idk what i have to do

:bust_in_silhouette: Reply From: Ertain

error: Invalid call. Nonexistent function ‘stop’ in base ‘PackedScene’.

A little help for your error there. You probably need to either instantiate the Player1 variable, or you need to instantiate it in-line. An example of this is:

onready var Player1 = preload("res://Player/Player1.tscn").instance()

Or do something like this:

var player_instance
_ready():
     # Use this in the "_on_player1_pressed()" function.
     player_instance = Player1.instance()

Hope this helps.

Invalid call. Nonexistent function ‘stop’ in base ‘RigidBody2D (Player1.gd)’

i searched up in the docs for the RigidBody2D did some shenanigan with the sleep and can_sleep properties but failed (again)

And when i do this

onready var Player1 = preload("res://Player/Player1.tscn").instance()

Invalid call. Nonexistent function ‘instance’ in base ‘RigidBody2D (Player1.gd)’

func spawn_player1(num):
	for i1 in range(num):
		var p1 = Player1.instance() <------------ error
		p1.connect("player1_pressed", self, "_on_player1_pressed") 
		player_container1.add_child(p1)

i just realized, maybe it has something to do with this:

func spawn_player1(num):
for i1 in range(num):
	var p1 = Player1.instance()
	p1.connect("player1_pressed", self, "_on_player1_pressed") 
	player_container1.add_child(p1)

Rayu | 2020-11-22 06:43