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.
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
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