Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

4 comments

1

lmao much appreciate<3

1

Gonna test the problem, might take some time

0

Much obliged man

0

You are not doing anything if GetUserIdFromNameAsync fails and you are not pcalling GetPlayerPlaceInstanceAsync. Use "pcall(teleportService.GetPlayerPlaceInstanceAsync, teleportService, targetUserId)"

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.