The simple way to change scene:
var targetScene = "res://Levels/NextLevelScenePath.tscn" # note: It's String
get_tree().change_scene(targetScene)
The real question is about when to use the above codes.
It based on what effects you want to show.
I mean if you want a effects like:
player pig eat truffle -> truffle disspear -> do effects you want -> change to new scene.
Suppose you just have one(unique) truffle to eat.
Then you can code like following:
(if there are lots truffles then you can check the quantity, if got enough quantity then change scene, else queue_free the truffle.)
[In truffle script]
extends Area2D
var targetScene = "res://Levels/NewScenePath.tscn"
func _input(event):
if event.is_action_pressed("ui_select"):
if get_overlapping_bodies().size() > 0:
visible = false # hide truffle
# do effects you want
change_to_next_level()
func change_to_next_level():
get_tree().change_scene(targetScene)
queue_free
Hope this help.