TeleportToPlaceInstance issue with API example

So the teleport example script for “Following Another Player” in the API at https://developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportToPlaceInstance
is shown below :

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
 
Players.PlayerAdded:Connect(function(player)
	-- Is this player following anyone?
	local followId = player.FollowUserId
	-- If so, find out where they are
	if followId and followId ~= 0 then
		local success, errorMessage, placeId, jobId = pcall(function()
			return TeleportService:GetPlayerPlaceInstanceAsync(followId)
		end)
		if success then
			-- Teleport player
			TeleportService:TeleportToPlaceInstance(placeId, jobId, player)
		end
	else
		warn("Player " .. player.UserId .. " is not following another player!")
	end
end)

I have put this into a Script in the ServerScriptService but it does not seem to be working correctly. I didn’t edit the code at all from the example, the warn portion is working great but when teleporting a player at line 14 TeleportService:TeleportToPlaceInstance(placeId, jobId, player) it gives me the error “Unable to cast string to int64”. What am I missing? Am I supposed to add my own values instead of the variables placeId/jobId/player on line 14? Or do I just need to do some sort of string/int64 conversion within the function? Any help would be greatly appreciated!

It appears the wiki code is incorrect. The reason as to why it isn’t working is the expected arguments are pushed forward by one, so placeId is an empty string and jobId is the place id.

To counter this, change the pcall to this:
local success, errorMessage, _, placeId, jobId = pcall(function()

3 Likes

Worked like a charm! Thank you so much, would you happen to know how to tell if the server is full since there is no error message?

It’d be a bit tougher to check that, but still possible.

There’s a web api that returns active servers in a place, you could identify the server through the returned servers by jobId and then you can compare the player count from there.

https://games.roblox.com/docs#!/Games/get_v1_games_placeId_servers_serverType

1 Like

I just found this feature in the API https://developer.roblox.com/en-us/api-reference/event/TeleportService/TeleportInitFailed and it says that it fires if a request to teleport fails, and returns a TeleportResult which will tell me if the server is full or if it failed from another reason. I just added the code to my game but haven’t tested it yet, hopefully it works without any hidden issues lol.