How to teleport players (to another server)

Hello! I want to make another “place” in my experience, in other words a sub-game inside my experience. I know I can use teleport service to teleport players to that place using “place id”, but I also want to make it so players can teleport to the same server as their friends. For example, I am in the “starter place” of the experience, and my friend is in another “place”. I want to be able to teleport to that “another place” in the same server as my friend. How do I do that? (By the way I know how to get friends) Thanks!

Edit: I just realized that teleport service also includes something called “Teleport Data”. I don’t know how it works, but if it’s possible to use it to teleport players to their friend’s server, how would I go about doing that?

1 Like

You can detect the person the player tried to join when they entered the experience, using Player.FollowUserId. Then you can teleport the player to their friend using this:

local ts = game:GetService("TeleportService")
-- later:

local this, _, placeid, jobid = ts:GetPlayerPlaceInstanceAsync(player.FollowUserId)
if this then return end -- User in this server?

ts:TeleportToPlaceInstance(placeid, jobid, player)

If this works, you should wrap it in a pcall or task.spawn.

Thanks, I need to go to sleep now, I will test it tomorrow. if it works I’ll remember to set it as the solution.

Hi, there’s an small error in my code, I was using player:GetFriendsOnline(), but the error says

“GetFriendsOnline must be invoked on the Local Player”

I am running this from a server script by the way. How do I fix this? Should I run it from the client?

Edit: It worked when I ran it from the client :slight_smile:

So, did the code work the way you wanted?

I tested it but how do I join a server in that place if my friend isn’t there? aka none of my friends are in that “place” how do I join it with teleport service?

Just research more of the TeleportService methods. There’s one to just teleport to a place, and it would pick an ideal server.

ok‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎

I’m not sure, but I think you could be able to use math.random() for that

1 Like

It works. Thanks! :slight_smile: ‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.