Feature request:
A method for querying players within a specific server. It would return a table of PlayerIDs.
Use Case:
As a developer, I want to be able to know what players are currently in my matches, so that I can repopulate the matches appropriately on the fly.
Example:
local players = teleportService:GetPlayersInReservedServer(reservedServerAccessCode)
Ideally, it will throw an error if the server doesn’t belong to the creator, or the server doesn’t exist (e.g. invalid reservedServerAccessCode).
Current Problem:
With reserved servers, I do not know who is still in them. I can send players to it, but I don’t know which players have left. Therefore, I don’t know the current number of players in the match. If I want the match to keep itself alive, I need to be able to query the players in the match so that I know how to repopulate it.
Current Workaround:
Currently, there are two ways to handle this situation. The first solution is to use DataStores to communicate this data. This seems to have been unreliable for other devs though. The second solution is using the HttpService (my preference), but that requires that a user can host a server and build a system to handle matchmaking–that’s a bit overkill for most.
Solution:
Supply a way for developers to query the players in a reserved server. Considering the main website displays users in each server, I would imagine this wouldn’t be a huge challenge, but I don’t know the underlying system that handles it.
Extended example:
A match is created. Every 10 seconds, the match is queried to see how many players are in the match. If not enough, players are added again.
local teleportService = game:GetService("TeleportService")
-- The Match class:
local Match = {}
Match.__index = Match
-- Create new match instance:
function Match.new(placeId)
local match = setmetatable({
AccessCode = teleportService:ReserveServer(placeId);
PlaceId = placeId;
}, Match)
return match
end
-- Utilize suggested feature:
function Match:GetPlayers()
return teleportService:GetPlayersFromReservedServer(self.AccessCode)
end
function Match:AddPlayers(...)
local players = {...}
teleportService:TeleportToPrivateServer(self.PlaceId, players)
end
------------------------------------
-- Create a new match:
local match = Match.new(000000)
-- Add players:
match:AddPlayers(player1, player, player3)
-- Continuously monitor server:
spawn(function()
while (true) do
wait(10)
local playersInMatch = match:GetPlayers()
if (#playersInMatch < 3) then
for i = 1,3 - #playersInMatch do
-- Add a player
end
end
end
end)
Caveats:
- What happens when the match server closes?
- Should data also be queried about the max players allowed in the server?
- Throttle limits?
- Could
:GetPlayerPlaceInstanceAsync()
be a viable alternative?
Other features that would help facilitate matchmaking:
-
ReserveServer
should return a JobId too
Final Note:
With the currently available APIs, it is not possible to do proper matchmaking. It feels as if we have been given a half-finished set of tools to do matchmaking. I do not say that to talk badly about the devs/engineers–you guys are awesome–but simply to point out the reality of the current condition.