Hey ya’ll! I’m currently making a across server match making system. I have made some basic code (which I hope works) that will add a players player ID to a table on all servers. I am currently stuck on matching two players together. I tried matching but I ran into a problem. If they both look for a match. What if player1 gets another player while player2 gets player1. It will be all screwed up. How can I make it find both opponents and match them together without them getting a different opponent?
Note: I am going to use Teleport Service to create a server for them and teleport them there with their userID that’s why I have their userID’s in the table.
Current Code:
local PS = game:GetService("Players")
local MS = game:GetService("MessagingService")
local TS = game:GetService("TeleportService")
local Event = game:GetService("ReplicatedStorage").StartMatchmaking
local GameId = 7684162178
local InQueue = {}
function CreateMatch(player, status)
local foundMatch = false
local function Waiting()
repeat
status.Text = "Looking for Match! Please Wait"
wait(0.25)
status.Text = "Looking for Match! Please Wait."
wait(0.25)
status.Text = "Looking for Match! Please Wait.."
wait(0.25)
status.Text = "Looking for Match! Please Wait..."
wait(0.25)
until foundMatch
end
coroutine.wrap(Waiting)()
end
MS:SubscribeAsync("PlayersInQueue", function(PlayerId)
table.insert(InQueue, PlayerId.Data)
print(InQueue)
end)
Event.OnServerEvent:Connect(function(player, status)
--// Insert UserID to All Servers
if (not table.find(InQueue, player.UserId)) then
MS:PublishAsync("PlayersInQueue", player.UserId)
print("User Added to Waiting For Match")
else
print("User Already Waiting For Match")
end
CreateMatch(player, status)
end)