"TeleportToPrivateServer must be passed an array of players"

Hi. I’m trying to insert a specific group of players to a table and teleport them to a private server. Everything’s fine until it tries to teleport them, because it says “TeleportToPrivateServer must be passed an array of players.”. I don’t know what I’m doing wrong, I don’t think the table is empty because when I tell it to print the first element and touch the part, it does print my name.

local function onTouch(partTouched)
	local humanoid = partTouched.Parent:FindFirstChild("Humanoid")	
	if humanoid then
		local character = Players:GetPlayerFromCharacter(partTouched.parent)
		if not table.find(playersTouching, character) then
				table.insert(playersTouching, character)
				print("Inserted to table")
		        partTouched.Parent.HumanoidRootPart.CFrame = tphere.CFrame
		end	
	end
end
game.Workspace.partthing.Touched:Connect(onTouch)

Here’s the teleport part of the script.

while wait(20) do
	if #playersTouching >= 1 then
		print(playersTouching[1])
		wait(1)
		print(playersTouching[2])
		local TS = game:GetService("TeleportService")
		local code = TS:ReserveServer(5484604783)
		print("Server created")
		TS:TeleportToPrivateServer(5484604783, code, playersTouching)
	end
end

Can you show the code where tphere and playersTouching is kept?

tphere is the name of the object the player is teleported to, and playersTouching is an empty table but it adds the player who touches a specific part to the table. Above this code, there isn’t any line where they’re kept, there are just variables for the table and the part.

The empty table needs to be declared somewhere above the code that you have.

The table’s declared at the first line of the whole script.

I tried testing this in a live game, and it worked. I have to go now, so be sure to try out different things and read the Roblox API to make sure you are doing the teleport stuff correctly.

Also, make sure you are using a game.PlaceId when you teleport someone. You can copy print(game.PlaceId) in the command bar to see the id.

1 Like