I'm trying to make the player teleport to a place when they die. Here's my code:

extends Area2D

var player


func _ready():
	player = get_node("/root/Node2D/Boho/KinematicBody2D")


func _on_Spike_body_entered(player):
	if player.is_in_group("Player"):
		player.position = (Vector2(-614, 538))

  • When the player (left sprite) is moved into the right sprite, using the right-arrow key, do you want the player to be teleported back to its original position?

    If that's the problem, the reason it's not working is that the "body_entered" signal isn't connected. To fix that, you can connect the signal in the _ready() method in Spike.gd:

    func _ready():
    	player = get_node("/root/Node2D/Boho/KinematicBody2D")
    
            # warning-ignore:return_value_discarded
    	connect("body_entered", self, "_on_Spike_body_entered")

    You can also connect a signal using the Inspector, but it's easier to explain how to do it with code.

Solution:

extends Area2D

var player

func _ready():
player = get_node("/root/Node2D/Boho/KinematicBody2D")

func _on_Spike_body_entered(player):
if player.is_in_group("Player"):
player.global_position = Vector2(-614, 538)

Why error: do not use () around Vector2, Dont use "player.position" if you teleporting player for another place, use "global_position" for this.

    godol

    if this cause error, put () around Vector2.

    DaveTheCoder
    I want the object to teleport the player somewhere (not another scene, but location on the scene the player is in), but the object isn't doing that when the player enters collison.

    godol I looked here, and it looks like area2d doesn't have a collision, put the collision and make it collide with the player.

      It would save a lot of time if you could post a .zip of your project, or a minimal project that illustrates the problem, along with a clearer explanation of the problem.

        DaveTheCoder
        do you see the icon png in mountain enterence? When you touch it, its suposed to teleport you to the start of the level. Also just need to know, do you see the photo in this reply?

        Yes, I see the bottom portion of the scene tree in the image in your reply, and the attached script (Spike.gd). I'm attaching a screenshot of the running game (I turned off full-screen).

        I'm not sure what you mean by "icon png in mountain entrance". Is that the animated player on the left?

        When the player (left sprite) is moved into the right sprite, using the right-arrow key, do you want the player to be teleported back to its original position?

        If that's the problem, the reason it's not working is that the "body_entered" signal isn't connected. To fix that, you can connect the signal in the _ready() method in Spike.gd:

        func _ready():
        	player = get_node("/root/Node2D/Boho/KinematicBody2D")
        
                # warning-ignore:return_value_discarded
        	connect("body_entered", self, "_on_Spike_body_entered")

        You can also connect a signal using the Inspector, but it's easier to explain how to do it with code.