Why does TeleportToPrivateServer must be passed an array of players?

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

You calling the function without sending the plr object do CreateNewServer(plr) and SendToServer(plr)

1 Like

How would I send the plr object to the two functions from the event?

Well, when the client fire the remote event for the server side, its sending the player obj of the player that fire the event

here you can see that you are getting the plr object as “plr” so you just need to add plr in your ()

Event.OnServerEvent:Connect(function(plr)
	if #Servers == 0 then 
		CreateNewServer(plr)
	else if #Servers >=1 then 
		SendToServer(plr)		
	end
end)
1 Like

Also, remove the last end, and elseif is not separated:

Event.OnServerEvent:Connect(function(plr)
	if #Servers == 0 then 
		CreateNewServer(plr)
	elseif #Servers >=1 then 
		SendToServer(plr)		
	end
end)
2 Likes

It worked! Thanks for the solution!

1 Like

Thank you for your helpful tips!

1 Like