In my script I want to do the following:
- When a key player (player = “yLenaYT”) enters the game for the first time, he must create a reserved server and move there;
- The next players who join the game must retrieve the server’s ID where the key player is (yLenaYT) and transport themselves there.
The first part works, but the second player trying to run TeleportAsync
is generating error 773 (Attempting to teleport to a restricted location)
local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local UserId = player.UserId
if player.Name == "yLenaYT" then
if game.PrivateServerId == "" then
TS.TeleportInitFailed:Connect(function(player, result, errorMessage)
warn("player, result, errorMessage", player, result, errorMessage)
end)
local Key = TS:ReserveServer(game.PlaceId)
TS:TeleportToPrivateServer(game.PlaceId, Key, {player})
end
else
local UserId = Players:GetUserIdFromNameAsync("yLenaYT")
local currentInstance, I, placeId, jobId
local success, errorMessage = pcall(function()
currentInstance, I, placeId, jobId = TS:GetPlayerPlaceInstanceAsync(UserId)
end)
if success then
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions.ServerInstanceId = jobId
local teleportResult = TS:TeleportAsync(game.PlaceId, {player}, teleportOptions)
else
print(errorMessage)
end
end
end)
I’ve already researched this error, but I couldn’t find a similar solution to my problem.
Can anyone help?