How do I pass info onto another game using TpService?

How do I pass info onto another game using TpService

So I’m just trying to use TeleportService to transfer data from my lobby onto my other game.

Code for Lobby (server script)

tp.Event:Connect(function()
	local tpOptions = Instance.new("TeleportOptions")
	
	local playerNumber = #playerTable
	tpOptions:SetTeleportData(playerNumber)
	
	local privateServer = teleportService:ReserveServer(15091617375)
	teleportService:TeleportToPrivateServer(15091617375,privateServer,playerTable,"Main Spawn",tpOptions)
	table.clear(playerTable)
end)

And here is the code for the other game (local script) inside starterpack:

local tpService = game:GetService("TeleportService")
local rp = game:GetService("ReplicatedStorage")
local info = rp:WaitForChild("TpInfo")

local tpData = tpService:GetLocalPlayerTeleportData()

if tpData then
	print("yes data")
	local numOfPlayers = tpData.playerNumber
	info:FireServer(numOfPlayers)
else
	print("no data")
end

It prints no data even though I put data into the tpOptions variable in the server script.

Use a table instead.

tp.Event:Connect(function()
	local tpOptions = {}
	
	local playerNumber = #playerTable
	tpOptions['playerNumber'] = playerNumber
	
	local privateServer = teleportService:ReserveServer(15091617375)
	teleportService:TeleportToPrivateServer(15091617375,privateServer,playerTable,"Main Spawn",tpOptions)
	table.clear(playerTable)
end)

I’ll try it, thanks @igd3v

This set of programs do this … both are editable.
GameA
GameB

This is a portal testing set with a few tests. One is what you’re looking to do.

Gives me this error?
image
On this line

tpOptions['playerNumber'] = playerNumber

here is the code:

tp.Event:Connect(function()
	local tpOptions = Instance.new("TeleportOptions")
	
	local playerNumber = #playerTable
	tpOptions['playerNumber'] = playerNumber
	
	local privateServer = teleportService:ReserveServer(15091617375)
	teleportService:TeleportToPrivateServer(15091617375,privateServer,playerTable,"Main Spawn",tpOptions)
	table.clear(playerTable)
end)

TeleportOptions is not a table. It is an instance. The three properties are:

  • ReservedServerAccessCode
  • ServerInstanceId
  • ShouldReserveServer

You’re creating TeleportOptions instance instead of a table. He asked you to create a table and then set the playerNumber value inside of that table. Then you set the TeleportData to that table and the other game should be able to find that table

I see, I didn’t realize the top bit of code, that was purely my fault. I’ll fix it and then try again

So does it have to be a table or can you just input some information into the tpService object?

See in the last param can I just put in a number and then it will take that data to the next game or does it have to be a table?

teleportService:TeleportToPrivateServer(15091617375,privateServer,playerTable,"Main Spawn",15)

also I have this now but it still says I get no data

tp.Event:Connect(function()
	local tpOptions = {}

	local playerNumber = #playerTable
	tpOptions['playerNumber'] = playerNumber

	local privateServer = teleportService:ReserveServer(15091617375)
	teleportService:TeleportToPrivateServer(15091617375,privateServer,playerTable,"Main Spawn",tpOptions)
	table.clear(playerTable)
end)

and then here is the script that gets it:

local tpService = game:GetService("TeleportService")
local rp = game:GetService("ReplicatedStorage")
local info = rp:WaitForChild("TpInfo")

local tpOptions = Instance.new("TeleportOptions")

local tpData = tpService:GetLocalPlayerTeleportData()
if tpData then
	print("yes data")
	print(tpData)
	local numOfPlayers = tpData.playerNumber
	info:FireServer(numOfPlayers)
else
		print("no data")
end

it prints “no data”
did I do something wrong?