Private Server keeps giving me must be passed an array of players error

I’m trying to teleport to a private server using TeleportToPrivateServer, but I keep getting the error must be passed an array of players.

I also searched forums and devhub to find the cause, but couldn’t solve it.

This is a script (not a local script).

Please Help.

local function LPCC_UP_UI()

	local LPCC_FRAMES_A = {}

	for i, LPCC_VALUE in pairs(game.ReplicatedStorage.Servers:GetChildren()) do
		local LPCC_N = LPCC_VALUE.Name
		local LPCC_SS = string.split(LPCC_VALUE.Value, " ")
		local LPCC_ID = LPCC_SS[1]
		local LPCC_PLRS = LPCC_SS[2]
		local LPCC_FRAME_B = script.ServerTemplate:Clone()

		LPCC_FRAME_B:WaitForChild("ServerName").Text = LPCC_N .. "\n ID: " .. LPCC_ID
		LPCC_FRAME_B:WaitForChild("Players").Text = LPCC_PLRS .. "/" .. game.Players.MaxPlayers

		table.insert(LPCC_FRAMES_A, LPCC_FRAME_B)
		LPCC_FRAME_B.JoinButton.MouseButton1Click:Connect(function(player)
			game:GetService("TeleportService"):TeleportToPrivateServer(game.PlaceId, LPCC_ID, {player}) -- error
		end)
		script.Parent.LPCC_FRAME_LIST:ClearAllChildren()
		script.UIListLayout:Clone().Parent = script.Parent.LPCC_FRAME_LIST
		for i, LPCC_FRAME_B in pairs(LPCC_FRAMES_A) do
			LPCC_FRAME_B.Parent = script.Parent.LPCC_FRAME_LIST
		end
	end
end

LPCC_UP_UI()

game.ReplicatedStorage.Servers.ChildAdded:Connect(LPCC_UP_UI)
game.ReplicatedStorage.Servers.ChildRemoved:Connect(LPCC_UP_UI)

The error means that it must be the player, not a string name of the player or others.

game:GetService("TeleportService"):TeleportToPrivateServer(game.PlaceId, LPCC_ID, {player}) 

You placed {player} so it’s not a array it’s a table. If you want to teleport everyone, you can simply change it to game.Players:GetPlayers() if not then make a table and use table.insert when adding the user!

1 Like

Thank you for answer. However, rather than teleport all players, I want to make it so that only the person who pressed the button is teleported when the button is pressed. It’s a bit confusing.

		LPCC_FRAME_B.JoinButton.MouseButton1Click:Connect(function(player)
			game:GetService("TeleportService"):TeleportToPrivateServer(game.PlaceId, LPCC_ID, {player}) -- error
		end)

I saw that your using :Connect(function(player). As i know, in buttons function, it does not return who pressed the button, so the player would be just nil. Are you using local script or normal script for this?

1 Like

I tested it myself and it came out nil. This is a normal script.

EDIT: I found that it only works with local scripts. It’s my fault.

1 Like