How to toggle Particles2D with Signals?

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

Hi all, I had a little question I’ve been thinking over for a day now.

In my game, I have the main scene. in it, I’m instancing a Particles2D, and I want to be able to toggle it on and off with the signals emitted for pressing the “Play” button, and when an enemy enters a certain area.

extends Node2D

const SCREEN_HEIGHT = 580
const SCREEN_WIDTH = 1010

signal game_over

var timescore
var kills
var finalscore
var EnergyShot = preload ('res://player-side/EnergyShot.tscn')
var eyeworm = preload ('res://Enemy.tscn')
var SpawnWaitTime = 5
var highscore = 0.0

func _ready():

func _on_SpawnTimer_timeout():
	var enemy = eyeworm.instance()
	enemy.position = Vector2(SCREEN_WIDTH + 10, rand_range(0, SCREEN_HEIGHT))
	enemy.connect("kill", self, "_on_kill")
	SpawnWaitTime -= 0.15
	if (SpawnWaitTime < 0.4):
		SpawnWaitTime += 4.85

func _on_SurvivalTimer_timeout():
	timescore += 1

func _on_kill():
	kills += 1

func _on_BaseArea_area_entered(area):
	finalscore = timescore + kills*5
	if highscore < finalscore:
		highscore = finalscore
	$HUD.player_loss(finalscore, highscore)
	$BaseArea/CollisionShape2D.disabled = true
	get_tree().call_group("EyeWorms", "queue_free")

func _on_HUD_play_game():
	timescore = 0
	kills = 0
	SpawnWaitTime = 5
	finalscore = 0
	$BaseArea/CollisionShape2D.disabled = false

func _on_HUD_credits():

extends CanvasLayer

signal play_game
signal credits

func show_message(text):
	$SystemMessage.text = text

func _on_MessageDuration_timeout():

func player_loss(finalscore, highscore):
	show_message("Game Over")
	yield($MessageDuration, "timeout")
	$SystemMessage.text = "Play Again?"
	$HighScore.text = str(highscore)
	$CurrentScore.text = str(finalscore)

func score_count(score):
	$TimeSurvived.text = str(score)

func kill_count(count):
	$Kills.text = str(count)

func _on_Button_pressed():
	$TimeSurvived.text = str("0")
	$Kills.text = str("0")

func _on_HelpButton_pressed():
	yield($Help/ShowHelpDuration, "timeout")

func _on_CreditsButton_pressed():

func _on_HUD_credits():
	get_tree().change_scene("Credits.tscn") (This is the Particles2D node)

extends Particles2D

var playing = false
:bust_in_silhouette: Reply From: timCopwell

First of all your should look like this if you want it to not have autoplay when beign instanced.

 extends Particles2D

    emitting = false
    one_shot = true # false if you want it to loop

Then signals to your button and area nodes.

func _on_Area2D_body_entered(body):
	    get_node("Thuster").emitting = true

func _on_Button_pressed():
       get_node("Thuster").emitting = true