Why won't the teleport work?

This is my first time using teleport service, so I don’t really know what’s going wrong

mssgserv:SubscribeAsync("rankedchannel", function(mssg)
	local plrs = mssg.Data --this is table with 2 UserIDs, both players are in different servers
	local tpoptions = Instance.new("TeleportOptions")
	tpoptions.ShouldReserveServer = true
	for i,v in pairs(game.Players:GetPlayers()) do
		if v.UserId == plrs[1] or v.UserId == plrs[2] then
			local tpsuccess, tperror = pcall(function()
				tpserv:TeleportAsync(125023235255834, {v}, tpoptions)
			end)
			if not tpsuccess then
				print("tperror")
			end
		end
	end
end)

The code is trying to teleport the 2 players to the same server, but errors at the the teleport async function. why?

To help with debugging use print(tperror) not print("tperror"). What does it output?

You have to reserve and get a reserved server code first, you can use something like this:

local placeId = 123456 -- your place id
local success, code = pcall(function()
    return teleportserv:ReserveServer(placeId)
end)
if success and code then
    print(code)
end

After acquiring the code set tpoptions.ReservedServerAccessCode to the code and teleport from there, you should also teleport all players in a single table not individually.

Hi! I did some tests, and improved your code.

local tpoptions = Instance.new("TeleportOptions")
	tpoptions.ShouldReserveServer = true

This don’t work with TeleportAsync. I don’t know why.
Also i added PlayersList to don’t call teleport function 2 times

mssgserv:SubscribeAsync("rankedchannel", function(mssg)
	local plrs = mssg.Data --this is table with 2 UserIDs, both players are in different servers
	local PlayersList = {}
	local Code = tpserv:ReserveServer(125023235255834)
	for i,v in game.Players:GetPlayers() do
		if v.UserId == plrs[1] or v.UserId == plrs[2] then
			table.insert(PlayersList, v)
		end
	end
	local tpsuccess, tperror = pcall(function()
		tpserv:TeleportToPrivateServer(125023235255834, Code, PlayersList)
	end)
	if not tpsuccess then
		print(tperror)
	end
end)

Please note that Teleport won’t work in studio, it’s working only in actual game