I’ve seen this in a lot of games, but unfortunately I don’t understand exactly how to do this.
So I have a lobby and a game level. I register a team of four people in the lobby and teleport them to the game level.
Then the next command and so on. But how to make sure that there are several teams on the same level, but each team is isolated. The teams should not see each other and interact in any way. I hope I explained it clearly. An example of this is the Tower Defense games where teams of several people gather and teleport to the map. But each team plays its own separate game at the same level.
In this case, the map would be a seperate place. You would reserve the server and then teleport the players there, also sending any data through the TeleportData.
The game server then retrieves this data and any other player data from the data store or maybe a MemoryStore HashMap and the round happens. The game server then updates the data store, or the HashMap, and sends the players back to the main place. Data is retrieved, etc. etc.
(If a HashMap was used for data saving, the main place would save the data).
Thanks for your reply. I haven’t worked with TeleportService yet. Does this mean that I’m creating a game level as a separate place? And then I use this service to reserve separate servers for players and move them there?
Yes. You would create it as a separate place, but still under the same universe. You treat the new server as a private server and use the TeleportService
to move the players to it.
--service
local tpService = game:GetService("TeleportService")
--place ID
local placeId = game.PlaceId --replace this with the ID of your new place
--then...
local function teleport(players: {Player})
--reserve the server
local code = tpService:ReserveServer(placeId)
--teleport the players
local success, result = pcall(
tpService.TeleportToPrivateServer,
tpService,
placeId, --the target PlaceID
code, --code from TeleportService:ReserveServer()
players, --players to be teleported, in a table
nil, --spawn name
nil, --teleport data
nil --custom loading screen
)
if not success then
warn("Failed to teleport players")
end
end
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.