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)