Currently trying to make a memorystoreservice matchmaking system but experiencing difficulty with it.
My current method is:
2 Types of queues:
- 1 is the matches that exist for each type of match, (sorted map)
- 2 is the queue itself containing the user id for that player
When a user requests to join a queue, I check to see if any of the games in the 1st queue (the sorted map), by checking if the 2nd value stored in it is false, if it is false, then I’ll add the user to the 1v1 queue for that map and then attempt to tp them to that place, if there isn’t a map, then make a new one.
What I need help with is:
-
How can I teleport the user to the specific server that has room in it, do I need a specific id, what do I do here?
-
Is this the best way, can I do it a different way?
My current code (Rough Draft - Not clean code yet 😎)
local MemoryStoreService = game:GetService("MemoryStoreService")
local DataStoreService = game:GetService("DataStoreService")
local TeleportService = game:GetService("TeleportService")
local Match1V1 = MemoryStoreService:GetSortedMap("1V1MATCHES")
local Match2V2 = MemoryStoreService:GetSortedMap("2V2MATCHES")
local Match3V3 = MemoryStoreService:GetSortedMap("3V3MATCHES")
local Match4V4 = MemoryStoreService:GetSortedMap("4V4MATCHES")
local Match5V5 = MemoryStoreService:GetSortedMap("5V5MATCHES")
local Match6V6 = MemoryStoreService:GetSortedMap("6V6MATCHES")
local Matchmaking_Queue1 = MemoryStoreService:GetQueue("Matchmaking_Queue1V1")
local Matchmaking_Queue2 = MemoryStoreService:GetQueue("Matchmaking_Queue2V2")
local Matchmaking_Queue3 = MemoryStoreService:GetQueue("Matchmaking_Queue3V3")
local Matchmaking_Queue4 = MemoryStoreService:GetQueue("Matchmaking_Queue4V4")
local Matchmaking_Queue5 = MemoryStoreService:GetQueue("Matchmaking_Queue5V5")
local Matchmaking_Queue6 = MemoryStoreService:GetQueue("Matchmaking_Queue6V6")
local matchMap = {}
local queueMap = {}
matchMap["1v1"] = Match1V1
matchMap["2v2"] = Match2V2
matchMap["3v3"] = Match3V3
matchMap["4v4"] = Match4V4
matchMap["5v5"] = Match5V5
matchMap["6v6"] = Match6V6
queueMap["1v1"] = Matchmaking_Queue1
queueMap["2v2"] = Matchmaking_Queue2
queueMap["3v3"] = Matchmaking_Queue3
queueMap["4v4"] = Matchmaking_Queue4
queueMap["5v5"] = Matchmaking_Queue5
queueMap["6v6"] = Matchmaking_Queue6
local MatchmakingService = {}
function MatchmakingService.AddPlayerToQueue(player, queueType)
-- The false in setasync will assume that the match A, hasn't started and B, there isn't enough players in the server
-- The match will start if there is enough players, updating the value to true, disallowing joining
-- Remember to remove it from the sorted map in game
--matchMap[queueType]:SetAsync("Match", false, 100) -- Reset 100
local checkForCurrentMatch = matchMap[queueType]:GetRangeAsync(Enum.SortDirection.Descending, 200)
print(checkForCurrentMatch)
for match, isStarted in ipairs(checkForCurrentMatch) do
print(match, isStarted)
if isStarted == false then
queueMap[queueType]:AddAsync(player.UserId, 150, 1)
print("Success!")
else
for match, isStarted in ipairs(checkForCurrentMatch) do
print(match, isStarted)
end
end
end
end
matchMap[queueType]:SetAsync("Match", false, 100)
Would mean a match is open, essentially this whole sorted map will just be available games, because as soon as the value is true (the game is full) - it will remove itself from the sorted map