Help with TeleportService

Recently I’ve tried using teleport service in my game. I am trying to create a round based match with 2 opposing teams, and maybe even spectators. My plan is to use TeleportPartyAsync to teleport 2 or more players into a different place, with the teams already defined.
However I got a bit stuck in the process with GetLocalPlayerData, which looks like it is supposed to be for LocalScripts. How would I go about getting the teams from the new place that the players were teleported if GetLocalPlayerData is for clients?

im not sure what you mean.

if there are 2 servers running (say) and each set of players teleport to the other, what information are you missing?

You should set this up using a reserved server rather than your current plan to use a party teleport.

  • A party teleport will attempt to teleport players into a server that has room for them, if you also have room for spectators then they may end up in an existing game.
  • A reserved server is a private server that players can only join if they’ve been granted access, something which you can do.

The way to handle this is the following:

local placeId = ...
local accessCode, privateServerId = TeleportService:ReserveServer(placeId)

TeleportService:TeleportToPrivateServer(placeId, accessCode, players)

Since it sounds like you need to share data between these places, you can do this by either sending the data as the teleport data parameter of TeleportToPrivateServer or you can use the privateServerId returned by ReserveServer to store the data in a datastore.

To save the data, you might do the following:

local matchDataStore = DataStoreService:GetDataStore("Matches")
matchDataStore:SetAsync(privateServerId, data)

Then, to retrieve it:

local matchDataStore = DataStoreService:GetDataStore("Matches")
local data = matchDataStore:GetAsync(game.PrivateServerId)