I copied a tutorial for level changing and the code shows errors even though it works well.
extends Area2D
func _on_body_entered(body):
if body.is_in_group("player"):
var current_scene_file = get_tree().current_scene.scene_file_path
var next_level_number = current_scene_file.to_int() + 1
var next_level_path = "res://Scenes/Levels/level" + str(next_level_number) + ".tscn"
get_tree().change_scene_to_file(next_level_path)

These are the errors I get:
E 0:00:09:0325 star.gd:10 @ _on_body_entered(): This function can't be used during the in/out signal.
<C++ Error> Condition "locked" is true.
<C++ Source> scene/2d/area_2d.cpp:328 @ _clear_monitoring()
<Stack Trace> star.gd:10 @ _on_body_entered()
E 0:00:09:0325 star.gd:10 @ _on_body_entered(): Removing a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Remove with call_deferred() instead.
<C++ Source> scene/2d/collision_object_2d.cpp:98 @ _notification()
<Stack Trace> star.gd:10 @ _on_body_entered()
E 0:00:27:0500 star.gd:10 @ _on_body_entered(): This function can't be used during the in/out signal.
<C++ Error> Condition "locked" is true.
<C++ Source> scene/2d/area_2d.cpp:328 @ _clear_monitoring()
<Stack Trace> star.gd:10 @ _on_body_entered()
E 0:00:27:0500 star.gd:10 @ _on_body_entered(): Removing a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Remove with call_deferred() instead.
<C++ Source> scene/2d/collision_object_2d.cpp:98 @ _notification()
<Stack Trace> star.gd:10 @ _on_body_entered()

seems like more things are going on than what you posted... not enough of information

    kuligs2
    I copied this tutorial and everything I have in my game is more or less similar.
    Basically my character just walks into the star which is a portal and teleports to the next level. Everything works as it should but I'm getting errors and I don't know why.