Hello, I’m making a matchmaking system, and I’ve came up with some code. Here it is:
Script:
local AoQ = game.ReplicatedStorage.AddtoQueue
local RFQ = game.ReplicatedStorage.RemoveFromQueue
local MessageService = game:GetService("MessagingService")
local TeleportService = game:GetService("TeleportService")
local PlayersToMatch = {}
local place = 10262480669
AoQ.OnServerEvent:Connect(function(player)
table.insert(PlayersToMatch, player)
MessageService:PublishAsync("ChosenPlayer", PlayersToMatch[math.random(#PlayersToMatch)])
end)
RFQ.OnServerEvent:Connect(function(player)
table.remove(PlayersToMatch, player)
end)
MessageService:SubscribeAsync("ChosenPlayer", function(player)
TeleportService:TeleportPartyAsync(place, {player.Data, PlayersToMatch[math.random(#PlayersToMatch)]})
end)
LocalScript:
local isMatchmaking = false
local AoQ = game.ReplicatedStorage.AddtoQueue
local RFQ = game.ReplicatedStorage.RemoveFromQueue
script.Parent.MouseButton1Click:Connect(function()
if not isMatchmaking then
AoQ:FireServer()
script.Parent.Text = "Searching for matches..."
isMatchmaking = true
elseif isMatchmaking then
RFQ:FireServer()
script.Parent.Text = "Queue Up"
isMatchmaking = false
end
end)
And here is the error that comes up:
How can I fix this issue?