About
SimpleMatchmaking is a module built with ease of use and customizability in mind using ROBLOX’s MemoryStoreService.
Warning: this module has not been tested in a production environment. If you encounter any issue please let me know.
The name is wip
Freatures
- Consistent API: all the core functions in the module are named after the built-in MemoryStoreService and DataStoreService functions.
- High customizability: the module offers an options parameter with many customizable options.
- Decentralization: every server is able to assign a team to a match without needing a central server.
How it works
SimpleMatchmaking makes use of MemoryStoreService SortedMaps to publish the match info (such as players and the credentials to join) to all servers. Every server can then read and modify the entry they need to add players to a match. The matching process starts by looking in the sorted map for any existing game. If one or multiple games are found the module loops through the results until it finds a game with enough slots for the given players. If no suitable game is found the module will create an empty game, add the players, publish it to the SortedMap and teleport the players.
Warning: currently the module doesn’t stop the same player from queueing more than one time.
Use guide
ⓘ For anyone that wants to snoop in the original script, the test place linked under the title is uncopylocked.
- Lobby Server
Start by downloading the module from either the ROBLOX Marketplace, the Github page or the uncopylocked place and drop the module in ServerStorage. Follow up by requiring the module from a ServerScript and then call the GetQueue function by passing the queue name and the queue options. To start the matchmaking simply call the QueuePlayers function.
Code sample using a proximity prompt
local ServerStorage = game:GetService('ServerStorage')
local SimpleMatchmaking = require(ServerStorage.SimpleMatchmaking)
local QueuePrompt = workspace.TestQueue.BoundingBox.ProximityPrompt
local qSuccess, matchCredentials
local newOptions = SimpleMatchmaking:NewOptions()
newOptions.MatchPlaceId = 13609839542
newOptions.NumberOfTeams = 8
newOptions.MaxPlayersPerTeam = 1
newOptions.MatchExpirationTime = 600
local newQueue = SimpleMatchmaking:GetQueue("newQueue", newOptions)
QueuePrompt.Triggered:Connect(function(interactingPlayer)
local players = {}
table.insert(players, interactingPlayer)
qSuccess, matchCredentials = newQueue:QueuePlayers(players)
end)
- Match server
Put a copy of the module in ServerStorage and require it in a ServerScript. Connect a function to the PlayerAdded event and then get a new queue with the same options as in the lobby server. After that call the GetPlayerTeam function and pass the player parameter. The function will return if the operation was successful and the team of the player (if they are in one).
Code Sample
local ServerStorage = game:GetService('ServerStorage')
local SimpleMatchmaking = require(ServerStorage.SimpleMatchmaking)
local newOptions = SimpleMatchmaking:NewOptions()
newOptions.MatchPlaceId = 13609839542
newOptions.NumberOfTeams = 8
newOptions.MaxPlayersPerTeam = 1
newOptions.MatchExpirationTime = 600
local newQueue = SimpleMatchmaking:GetQueue("newQueue", newOptions)
game.Players.PlayerAdded:Connect(function(player)
local cSuccess, team = newQueue:CheckPlayerTeam(player)
if not cSuccess or not team then
return
end
player.Team = game.Teams[team]
end)
Updates roadmap
- An option to not save UserIds when queueing for games with teams of 1 player each.
- Make requests scale with the amount of players passed in QueuePlayers.
- Add a way to support rank and map selection (I don’t know how to describe this but I have some sort of idea on how to do it).
Feel free to ask any questions and leave suggestions.