1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Teleport to world not working

Discussion in 'Development' started by WhoAreMe, Jun 1, 2020.

  1. WhoAreMe

    WhoAreMe Witch

    Messages:
    55
    I tried to teleport player on another world using this
    PHP:
    public function onJoin(PlayerJoinEvent $event)
       {
        
    $player$event->getPlayer();
         
           
    $level $player->getServer()->getLevelByName("kit");
                
    $player->teleport($player->getLevel($level)->getSafeSpawn());
       }

    But i just teleport back to same world spawn when i do that
     
    Last edited: Jun 1, 2020
  2. KinokiYT

    KinokiYT Spider Jockey

    Messages:
    25
    GitHub:
    kinokiyt
    Having '$level = $player->getServer()->getLevelByName("kit");' is detecting the level that $player is currently in, it will teleport the player to the world that they are already in. To fix that, go off this:
    Code:
    $level = $this->getServer()->getLevelByName("kit");
     
  3. WhoAreMe

    WhoAreMe Witch

    Messages:
    55
    No luck :(
     
  4. KinokiYT

    KinokiYT Spider Jockey

    Messages:
    25
    GitHub:
    kinokiyt
    Try this:
    PHP:
    public function onJoin(PlayerJoinEvent $event) {
        
    $player $event->getPlayer();
        
    $player->teleport($this->getServer()->getLevelByName("kit")->getSafeSpawn());
       }
     
    WhoAreMe likes this.
  5. WhoAreMe

    WhoAreMe Witch

    Messages:
    55
    Wow thank you so much, all i need is that one line
     
  6. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    How is Player->getServer()->getLevelByName("kit") supposed to return the level where the player is? It makes no sense.
     
    Primus likes this.
  7. Primus

    Primus Zombie Pigman

    Messages:
    749
    Just to clarify - There is only one instance of the server, so
    PHP:
    $player->getServer() === $this->getServer() === Server::getInstance()
     
    Diduhless likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.