Best approach for a Teleporting System?

Hiwiwi guys!
Whats the best approach for a Teleporting System?
The system should allow to follow friends present only in the same place.
I made 3 different ones:

  1. Get a table of Online Friends from the User. Iterate each one and check placeID and compare with the current placeID. If match, create a buttonGUI

  2. Get All players in the server, iterate each one, check IsFriendsWith(), if match create buttonGUI

  3. Get a table of Online Friends from User. Iterate Players in server and use the userID to find a match in the OnlineFriends from User table, if match create buttonGUI

GetFriendsOnline()
IsFriendsWith()
GetFriendsAsync()

I got faster results with the method that I expected would be the less efficient…
So. Whats your advices in order to create Teleportation Systems?

Would you recomend:
Create empty table on client, each new onPlayerAdded add the new player to the table, instead of calling “Players:GetPlayers()” each time, iterate the Table of online users, and ask IsFriendsWith(mainUser), if match create buttonGUI… ?

Last question:
Is it possible, 2 users being in the same game, same place, and Different Server? I’m confused about this stuff… I guess yes… if so… How to get data from users in different servers playing the same game and same place? in order to Teleport?

Thank you for your time :3 :heart:

2 Likes

The best method for what you want to achieve is GetFriendsOnline().
And for your last question, you can use MessagingService.

1 Like

Actually, MessagingService is not needed at all. GetFriendsOnline returns an array of dictionaries which include the last location (PlaceId & JobId) of the friend when searching through a dictionary.

By using those two, you can initiate a teleport to that server with TeleportToPlaceInstance.

local function teleport(...)
    return game:GetService("TeleportService"):TeleportToPlaceInstance(...)
end
local function followFriend(player, friendName)
    local getFriends = player:GetFriendsOnline()
    for _, dictionary in ipairs(getFriends) do
        if dictionary.UserName == friendName then
            if dictionary.PlaceId == game.PlaceId then -- PlaceId will not be present if friend is not ingame
                teleport(game.PlaceId, dictionary.GameId, player)
            end
        end
    end
end
1 Like

Yeah well… I used GetFriendsOnline() of course… The 3 systems works differently, using different aproach.
Thank you for ur answer :3

Yup! Thank you, thats my main idea too!
Do u think that getting the last place id is more reliable/efficient/economic for the server than using MessagingService?
Thank you for ur reply :3

Yes, because when you call GetOnlineFriends, the dictionaries are already provided there and then.

By using MessagingService instead, you are ignoring these dictionaries given and you are trying to scan for the friend name specified if they are online then attempting to reach a server to ping back that they have found so friend.

This is unnecessary when GetOnlineFriends even tells you what they were last doing, which if they are online (guaranteed online as the function only gets online friends), it would show what they are doing now, at the time of calling the function.

1 Like

That makes totally sense!! Thank you so much for clarify it! :333

1 Like