Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Teleport to private server must be passed an array of players?

I'm trying to get my teleporting to private server script to work, but there's always some kind of error. Now the error is Teleport to private server must be passed an array of players. Not really sure what that means, Im trying to teleport players to a private server. Code:

local remote = game.ReplicatedStorage.StartEvent
local gameplaceid = 3313994275
local TeleportService = game:GetService("TeleportService")
local Reserve = TeleportService:ReserveServer(3313994275)
local playersTable = {}

remote.OnServerEvent:Connect(function(player)
for _, player in pairs(game.Players:GetPlayers()) do -- get all players
    playersTable[i] = v
end
	TeleportService:TeleportToPrivateServer(gameplaceid, Reserve, playersTable)
end)

1 answer

An array of players means a table with the values being players

A table is a variable that can hold other variables

local exampleTable = {
	1,
	2,
	3,
	4,
	5 -- note that last value doesnt need a , or ; (, or ; works fine)
}

In your case, it requires a table full of players:

local playersTable = {}

We then add in the players into the playersTable

local playersTable = {}
for _, player in pairs(game.Players:GetPlayers()) do -- get all players
	playersTable[i] = v
end

We then can call the PrivateServer function (method), TeleportService:TeleportToPrivateServer(PlaceId, Reserve, playersTable)

3 comments

0

So, its not putting any players in my PlayersToTeleport table?

0

Table index is nil line 9

0

I changed the code

This discussion is preserved as it was. New answers, comments, and votes are closed.