Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
4

How to make a friend teleport script in the same universe? (Issues)

Asked by
Radstar1 270 Moderation Voter
6 years ago
Edited 6 years ago

PROBLEM It only allows me to teleport to people in the exact same server that i'm trying to teleport from. useless right? I would greatly appreciate some help.

DESC I tried to make a feature that uses the typed name of a player, fires it to the server, and gets their UserId to begin the first part.

--Gets the userId of "Who"
game.ReplicatedStorage.Events.TeleportToFriend.OnServerEvent:Connect(function(Player,Who)
`   local FriendId
    pcall(function() 
        FriendId = game.Players:GetUserIdFromNameAsync(Who)
    end)
    FollowFriend(Player,FriendId) -- Function that makes you follow your friend
end)

The second part of the script is the one following the friend's named they typed.

function FollowFriend(player, targetUserId)
    local teleportService = game:GetService("TeleportService")
    local success, errorMsg, placeId, instanceId =      teleportService:GetPlayerPlaceInstanceAsync(targetUserId)
    if success then
        teleportService:TeleportToPlaceInstance(placeId, instanceId, player)
    else
        print("Teleport error:", errorMsg)
    end
end

However this is where it won't let me teleport to anyone outside of my server?

Any suggesstions? Any help appreciated

1
lmao much appreciate<3 Radstar1 270 — 6y
1
Gonna test the problem, might take some time User#20388 0 — 6y
0
Much obliged man Radstar1 270 — 6y
0
You are not doing anything if GetUserIdFromNameAsync fails and you are not pcalling GetPlayerPlaceInstanceAsync. Use "pcall(teleportService.GetPlayerPlaceInstanceAsync, teleportService, targetUserId)" hiimgoodpack 2009 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Try using the IsFriendsWith() statement, shown in an example here: wiki.roblox.com/index.php?title=API:Class/Player/IsFriendsWith

Ad

Answer this question