"Unable to cast value to Objects"

So,I am making matchmaking script where when player clicks button that player gets into a table.When there is x players in the table script should TP players from that table to another server.But when there players should get sent to other server I just get error;“Unable to cast value to Objects”

Script:

local TS = game:GetService("TeleportService")
    local isReserved = game.PrivateServerId ~= "4999054674" and game.PrivateServerOwnerId == 131944414    
    
        players_InQueue = {}
        inMatchmaking = false

    game.ReplicatedStorage.Remote.ready.OnServerEvent:Connect(function(player)
        print("remote is fired")
            for i = 1,#players_InQueue,1 do
                if player.Name == players_InQueue[i] then
                    inMatchmaking = true
                end
            end
                        
            if inMatchmaking == false then
                print("adding to table")
                    table.insert(players_InQueue,#players_InQueue+1,player.Name)
            else
                print("player is already in table")
            end
                        
            for i = 1,#players_InQueue,1 do
                print(players_InQueue[i])
            end
                        
                inMatchmaking = false
                
            for i = 1,#players_InQueue,1 do
                if #players_InQueue == 1 then
                    if players_InQueue[i] == player.Name then
     
                        local TpPlayers = players_InQueue[1]    
                                
                       
                            TS:TeleportToPrivateServer(4999054674,isReserved,TpPlayers)
                    end
                end
              end
            
            end)    
                        
                    

    

                game:GetService("Players").PlayerRemoving:Connect(function(player)
              local allPlrs = game.Players:GetChildren()
    
              for i = 1,#players_InQueue,1 do
                  if player.Name == players_InQueue[i] then
                           table.remove(players_InQueue,i)
                      print("Player left the game")
                  end
              end                
        end)

You first need to get the access code of the reserved server by doing TeleportService:ReserveServer(), which will return the code. Then you put that code in the second parameter. Right now you have the isReserved variable, which only checks whether the current server is a reserved one or not, but it does not actually get the access code as well as reserve a server.

1 Like

Okay,I just did that.But I am still gettin’ same error.

I am running into this right now. I have it constructed like so:

Screen Shot 2020-05-23 at 11.23.55 PM

And still getting this same error. My access code is correct, returned from :ReserveServer().

What is going on here??

EDIT: The third argument of the teleport function must be a table, even if it is only one player. You’ve been warned.