I’ve got a game where players can either join a new match every 5 minute or join an existing match.
For joining a new match: When a match starts, I want to teleport them to another place and start a new server in that place, where the players will play. How can I code it out such that whenever my players are teleported to a specific placeId, they will be in a new server without any other players?
For joining an existing match: How can I check if the existing players in the server does not exceed the server capacity and then teleport the player to the specific server?
local TeleportService = game:GetService("TeleportService")
local placeID = place id
function onTouched(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
TeleportService:Teleport(placeID , player)
end
end
script.Parent.Touched:connect(onTouched)
You need to add a table of players into the parameters of this function so the script recognizes each player and teleports all of them to the specified place.
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local placeId = 0 -- replace
local playerList = Players:GetPlayers()
local success, result = pcall(function()
return TeleportService:TeleportPartyAsync(placeId, playerList)
end)
if success then
local jobId = result
print("Players teleported to "..jobId)
else
warn(result)
end
Yeah, that’s pretty much how it works. You just make a table with player objects, add them to the function and it will tp anyone in that table. It’s pretty handy for scenarios like if you wanted to make a planetory exploration game where specific players in a spaceship travel to a whole new planet.