(The below code is abstracted)
-- Server code: ServerScriptService > Script in the lobby game.
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions.ShouldReserveServer = true
teleportOptions:SetTeleportData({ ["NumberOfPlayers"] = #game.Players:GetPlayers() })
game:GetService("TeleportService"):TeleportPartyAsync(placeID, game.Players:GetPlayers(), teleportOptions)
-- Client code: PlayerScripts > LocalScript in the target game.
local teleportOptions = game:GetService("TeleportService"):GetLocalPlayerTeleportData()
print(teleportOptions)
-- Prints nil
Hi, I’m having trouble getting teleport data to work. Above shows the code I’m working on, but when I print the teleportOptions after the teleport it’s always just nil
and it’s really bugging me. It’s completely breaking the game and would love it if someone had any idea why this might be happening!
Thanks,
-Tom 
1 Like
This might be why? Since you’re passing a Dictionary
onto calling your SetTeleportData
function, it keeps mixing all the keys (Or indexes) which may be resulting back as nil
Maybe try this?
-- Server code: ServerScriptService > Script in the lobby game.
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions.ShouldReserveServer = true
teleportOptions:SetTeleportData(#game.Players:GetPlayers())
game:GetService("TeleportService"):TeleportPartyAsync(placeID, game.Players:GetPlayers(), teleportOptions)
-- Client code: PlayerScripts > LocalScript in the target game.
local teleportOptions = game:GetService("TeleportService"):GetLocalPlayerTeleportData()
if teleportOptions then
print(teleportOptions)
else
print("Returned back nil?")
end
You’d have to use TeleportAsync
, not TeleportPartyAsync
if you want to use TeleportOptions I believe
game:GetService("TeleportService"):TeleportAsync(placeID, game.Players:GetPlayers(), teleportOptions)