Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help debugging matchmaking module?

Asked by 4 years ago

I've just finished my first version of my matchmaking module but it is riddled with bugs. I have worked out a few but I have reached a wall and can not seem to figure it out. Please keep in mind, this is my first module I have ever made, I apologize if I did anything wrong.

The purpose of this code is to allow players from diffrent servers to connect into a matchmaking queue with eachother and finding a new lobby. I have yet to workout the teleporting process, so I am just kicking the player to see if it works.

SERVER SCRIPT CODE

local matchmaking = game:GetService("ReplicatedStorage").Matchmaking
local msgService = game:GetService("MessagingService")
local module = require(game.ServerScriptService.MatchmakingModule)
module.forwarddata()
module.combinedata()
local gamequeue = {}

local function sendmoduledata(player, mode)
    module.forwarddata(player.Name, mode)
end
matchmaking.OnServerEvent:Connect(sendmoduledata)

msgService:SubscribeAsync("Entering Queue", function(playerdata)
    module.combinedata(playerdata.Data)
end)

module.matchplayers()

MODULE CODE

local msgService = game:GetService("MessagingService")
local module = {}
local players = {}
local solo = {}
local duo = {}
function module.forwarddata(player, mode)
    local playerdata = {
    ["PlayerName"] = player,
    ["PlayerLevel"] = "undefined",
    ["Mode"] = mode,
    }
        msgService:PublishAsync("Entering Queue", playerdata)
end

function module.combinedata(playerdata)
    for i, v in pairs(playerdata) do
        players[v.PlayerName] = {
            ["Rank"] = v.PlayerLevel,
            ["Mode"] = v.Mode,
        }
    end
end

function module.matchplayers()
    for i,v in pairs(players)do
        if v.Mode == "Solo" then
            if #solo < 2 then
                if not solo[v.Name]then
                table.insert(solo, v.Name)
                else
                end
            else
            game.Players.solo[1]:Kick("TeleportTest")
            game.Players.solo[2]:Kick("TeleportTest")
            end
        else
        if v.Mode == "Duos" then
            if #duo < 4 then
                if not solo[v.Name]then
                table.insert(solo, v.Name)
                else
                table.insert(duo, v.name)
                end
                else
            game.Players.duo[1]:Kick("TeleportTest")
            game.Players.duo[2]:Kick("TeleportTest")
            game.Players.duo[3]:Kick("TeleportTest")
            game.Players.duo[4]:Kick("TeleportTest")
            end         
        end
    end
    end
end
return module

Current bug error

ServerScriptService.MatchmakingModule:16: bad argument #1 (table expected, got nil)

0
By the way, this is what I am passing through the remote event from the client side. FruitPuunch 0 — 4y
0
matchmaking:FireServer("Duo") FruitPuunch 0 — 4y
0
It is either "Duo" or "Solo" depending on which button is clicked btw. FruitPuunch 0 — 4y

Answer this question