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

TeleportAsync not working in matchmaking?

Asked by 3 years ago

Hello, im quite new to roblox programming. I made a matchmaking script (i took inspiration from CB:RO matchmaking that i've seen on youtube). Everything is fine, but the teleportation to my other game is not working and showing me that error: Unable to cast value to Objects

I tried to figure it for whole day but with no positive results. Here is my MM code:

eloData = game:GetService("DataStoreService"):GetDataStore("Elo")
UpdateRate = 3
GAME_ID = 7298612208
--///////////////////////////////////////////////////////////////////////////
local TPS = game:GetService("TeleportService")
local moduleScript = script:WaitForChild("ModuleScript")
local _M = require(moduleScript)
function genRank(elo)

end
function game.ReplicatedStorage.RequestInfo.OnServerInvoke(player)
    local PrimaryMap = script.Parent.Primary.Value
    return PrimaryMap
end

local playersInQueue = {}
local JoinQueueQueue = {}

function game.ReplicatedStorage.JoinQueue.OnServerInvoke(Player)
    local PlayerData = {
        PlayerObj = Player;
        PlayerName = "";
        Elo = 0;
        Range = 50;
        matched = false;
    }
    PlayerData["Elo"] = 25 --eloData:GetAsync(tostring(Player.userId))
    PlayerData["PlayerName"] = Player.Name
    table.insert(JoinQueueQueue, 1, PlayerData)

end
function game.ReplicatedStorage.LeaveQueue.OnServerInvoke(Player)
    local PlayerData = {
        PlayerObj = Player;
        PlayerName = "";
        Elo = 0;
        Range = 50;
        matched = false;
    }
    PlayerData["Elo"] = 25 --eloData:GetAsync(tostring(Player.userId))
    PlayerData["PlayerName"] = Player.Name
    table.remove(playersInQueue, 1, PlayerData)
    if #Matches > 0 then
        for i=1, #Matches do
            table.remove(Matches, 1, PlayerData)
        end
    end
end
Matches = {}
while true do
    print("Matchmaking tick")
    local function CreateMatch(FirstPlayer)
        print(FirstPlayer["PlayerName"])
        print("Creating new match!")
        local NewMatch = {}
        NewMatch["Average"] = FirstPlayer["Elo"]
        --print(tostring(FirstPlayer["Elo"]))
        NewMatch["Range"] = 50
        FirstPlayer["matched"] = true
        table.insert(NewMatch, 1, FirstPlayer)
        table.insert(Matches, 1, NewMatch)
    end
    wait(UpdateRate)
    print("Players in JoinQueueQueue = "..#JoinQueueQueue)
    if #JoinQueueQueue > 0 then
        for i=1, #JoinQueueQueue do
            print("Transfered "..JoinQueueQueue[i]["PlayerName"].." into a queue")
            print("Index = "..tostring(i))
            table.insert(playersInQueue, 1, JoinQueueQueue[i])
            JoinQueueQueue[i] = nil
        end
    end
    print("playersInQueue = "..#playersInQueue)
    game.ReplicatedStorage.playersInQueue.Value = #playersInQueue
    if #playersInQueue > 0 then
        for i=1, #playersInQueue do
            if playersInQueue[i]["matched"] == false then
                if #Matches ~= 0 then
                    for i_2=1,#Matches do
                        local Diff = Matches[i_2]["Average"] - playersInQueue[i]["Elo"]
                        if Diff < 0 then
                            Diff = Diff * -1
                        end
                        if Matches[i_2]["Range"] >= Diff then
                            --moze grac
                            print("Gracz kwalifikuje sie do gry")
                            table.insert(Matches[i_2], 1, playersInQueue[i])
                            playersInQueue[i]["matched"] = true
                            break
                        end
                    end
                else    
                    CreateMatch(playersInQueue[i])
                end
            end
        end
    end
    print("Amount of matches = "..#Matches)
    if #Matches > 0 then
        for i=1, #Matches do
            --if #Matches[i] == 0 then Matches[i] = nil end
            Matches[i]["Range"] = Matches[i]["Range"] + 2
            if #Matches[i] == 1 then
                game.ReplicatedStorage.isMatch.Value = true
                print("Utworzono mecz!")
                TPS:TeleportAsync(GAME_ID, Matches[i])
                --print("----"..tostring(playersInQueue[i]["PlayerName"]))
            end
        end
    end
end

Answer this question