Greetings fellow Devs.
I am trying to make a matchmaking system using TeleportService, which is enabled by a remote event. However, when I try to Teleport to the other place an error occurs.
TeleportService::TeleportToPrivateServer must be passed an array of players
Here is my script:
local TeleportService = game:GetService("TeleportService")
local ActiveServers = game.ReplicatedStorage.ActiveServers
local Servers = ActiveServers:GetChildren()
local Event = game.ReplicatedStorage.ReserveServer
local function CreateNewServer(plr)
wait()
local Code = TeleportService:ReserveServer(6242113803)
local NewServer = Instance.new("StringValue", ActiveServers)
NewServer.Name = "Server"..#Servers + 1
NewServer.Value = Code
print("Server Created")
TeleportService:TeleportToPrivateServer(6242113803, Code,{plr})
end
local function SendToServer(plr)
local Destination = Servers[math.random(1, #Servers)]
print("Server Found!")
end
Event.OnServerEvent:Connect(function(plr)
if #Servers == 0 then
CreateNewServer()
else if #Servers >=1 then
SendToServer()
end
end
end)
Does any of you know why this is happening?
Thank you,
-Yolo