Teleporting to a private server

So I have this code. Its supposed to teleport a table of players to a private server but it doesn’t do that. any suggestions how to improve that?

local TPS = game:GetService("TeleportService")
local Players = game:GetService("Players")


local idPlace = 11873076445


-- RESERVED SERVER DATA
local code
local pvSVid

-- DEBOUNCE IF SERVER ALREADY EXIST
local isServerExist = false

-- PLAYERS WHO ALREADY TRIGGERED THE TOUCH
local PlayersActivatedTouchTP = {}

function connnect(partTouched)
	local isPlayer = Players:GetPlayerFromCharacter(partTouched.Parent)
	if not isServerExist then
		local placeId = TPS:ReserveServer(11873076445)
		local success, result = pcall(function()
			return TPS:TeleportToPrivateServer(11873076445, placeId, {PlayersActivatedTouchTP})
		end)
			Part.CanTouch = false
			isServerExist = true
	end end
	
 function private(partTouched)
	for i = 1,12 do
	if partTouched.Name == "HumanoidRootPart" then
		local isPlayer = Players:GetPlayerFromCharacter(partTouched.Parent)
		if isPlayer then
			if not table.find(PlayersActivatedTouchTP, isPlayer) then
				table.insert(PlayersActivatedTouchTP, isPlayer)
				if Players:GetPlayerByUserId(isPlayer.UserId) then
					print({isPlayer})
						wait(1)
						connnect(partTouched)

				end
				end
				end
		end
	end


end```
2 Likes
connnect(partTouched)

is that typing mistake :sweat_smile:

1 Like

that’s the name of the function

1 Like

oh sorry my bad, and I think the problem is with the checking if the player already owns a private server in that specified experience…

3 Likes

nope, tags not the problem
thats’’’

1 Like

hm then I think you don’t need “PlayersActivatedTouchTP” inside the square bracket since you already mentioned it as global variable to a table. :sweat_smile:

Maybe try this:

local TPS = game:GetService("TeleportService")
local Players = game:GetService("Players")


local idPlace = 11873076445


-- RESERVED SERVER DATA
local code
local pvSVid

-- DEBOUNCE IF SERVER ALREADY EXIST
local isServerExist = false

-- PLAYERS WHO ALREADY TRIGGERED THE TOUCH
local PlayersActivatedTouchTP = {}

function connnect(partTouched)
	local isPlayer = Players:GetPlayerFromCharacter(partTouched.Parent)
	if not isServerExist then
		local placeId = TPS:ReserveServer(11873076445)
		local success, result = pcall(function()
			return TPS:TeleportPartyAsync(11873076445, placeId, PlayersActivatedTouchTP)
		end)
			Part.CanTouch = false
			isServerExist = true
	end end
	
 function private(partTouched)
	for i = 1,12 do
	if partTouched.Name == "HumanoidRootPart" then
		local isPlayer = Players:GetPlayerFromCharacter(partTouched.Parent)
		if isPlayer then
			if not table.find(PlayersActivatedTouchTP, isPlayer) then
				table.insert(PlayersActivatedTouchTP, isPlayer)
				if Players:GetPlayerByUserId(isPlayer.UserId) then
					print({isPlayer})
						wait(1)
						connnect(partTouched)

				end
				end
				end
		end
	end


end
2 Likes

it gives a weird error
it says I didn’t close [ somewhere but I did

it doesn’t work, it prints the value but nothing else

Does the “isServerExist” is false or true?

1 Like

It should return a pcall output though since you added it as a pcall

it says DATASTore request was added to queue

Why dont you not pcall the teleport and just teleport the players?

I need them to get teleported to a private server

The Pcall function is not needed tho

it says unable to cast value to objects then

Thats the problem, show me your whole script without pcall function again.

local Part = workspace["Elevator 2p left"].Teleport.Telepart

workspace["Elevator 2p left"].Teleport.Telepart.Touched:Connect(function() local Part = workspace["Elevator 2p left"].Teleport.Telepart end)
workspace["Elevator 3p left"].Teleport.Telepart.Touched:Connect(function() local Part = workspace["Elevator 3p left"].Teleport.Telepart end)
workspace["Elevator 4p left"].Teleport.Telepart.Touched:Connect(function() local Part = workspace["Elevator 4p left"].Teleport.Telepart end)
workspace["Elevator 5p left"].Teleport.Telepart.Touched:Connect(function() local Part = workspace["Elevator 5p left"].Teleport.Telepart end)
workspace["Elevator 6p left"].Teleport.Telepart.Touched:Connect(function() local Part = workspace["Elevator 6p left"].Teleport.Telepart end)
workspace["Elevator 1p left"].Teleport.Telepart.Touched:Connect(function() local Part = workspace["Elevator 1p left"].Teleport.Telepart end)

workspace["Elevator 2p"].Teleport.Telepart.Touched:Connect(function() local Part = workspace["Elevator 2p"].Teleport.Telepart end)
workspace["Elevator 3p"].Teleport.Telepart.Touched:Connect(function() local Part = workspace["Elevator 3p"].Teleport.Telepart end)
workspace["Elevator 4p"].Teleport.Telepart.Touched:Connect(function() local Part = workspace["Elevator 4p"].Teleport.Telepart end)
workspace["Elevator 5p"].Teleport.Telepart.Touched:Connect(function() local Part = workspace["Elevator 5p"].Teleport.Telepart end)
workspace["Elevator 6p"].Teleport.Telepart.Touched:Connect(function() local Part = workspace["Elevator 6p"].Teleport.Telepart end)
workspace["Elevator 1p"].Teleport.Telepart.Touched:Connect(function() local Part = workspace["Elevator 1p"].Teleport.Telepart end)

local TPS = game:GetService("TeleportService")
local Players = game:GetService("Players")


local idPlace = 11873076445


-- RESERVED SERVER DATA
local code
local pvSVid

-- DEBOUNCE IF SERVER ALREADY EXIST
local isServerExist = false

-- PLAYERS WHO ALREADY TRIGGERED THE TOUCH
local PlayersActivatedTouchTP = {}

function connnect(partTouched)
	local isPlayer = game.Players:FindFirstChild(partTouched.Parent.Name)
	if not isServerExist then
		local placeId = TPS:ReserveServer(11873076445)
		TPS:TeleportPartyAsync(11873076445, placeId, isPlayer)
		Part.CanTouch = false
		isServerExist = true
	end end

function private(partTouched)
	for i = 1,12 do
		if partTouched.Name == "HumanoidRootPart" then
			local isPlayer = game.Players:FindFirstChild(partTouched.Parent.Name)
			if isPlayer then
				if not table.find(PlayersActivatedTouchTP, isPlayer) then
					table.insert(PlayersActivatedTouchTP, isPlayer)
					if Players:GetPlayerByUserId(isPlayer.UserId) then
						print(isPlayer)
						wait(1)
						connnect(partTouched)

					end
				end
			end
		end
	end


end


workspace["Elevator 2p left"].Teleport.Telepart.Touched:Connect(private)
workspace["Elevator 3p left"].Teleport.Telepart.Touched:Connect(private)
workspace["Elevator 4p left"].Teleport.Telepart.Touched:Connect(private)
workspace["Elevator 5p left"].Teleport.Telepart.Touched:Connect(private)
workspace["Elevator 6p left"].Teleport.Telepart.Touched:Connect(private)
workspace["Elevator 1p left"].Teleport.Telepart.Touched:Connect(private)
workspace["Elevator 2p"].Teleport.Telepart.Touched:Connect(private)
workspace["Elevator 3p"].Teleport.Telepart.Touched:Connect(private)
workspace["Elevator 4p"].Teleport.Telepart.Touched:Connect(private)
workspace["Elevator 5p"].Teleport.Telepart.Touched:Connect(private)
workspace["Elevator 6p"].Teleport.Telepart.Touched:Connect(private)
workspace["Elevator 1p"].Teleport.Telepart.Touched:Connect(private)

where is the

in this?
I mean like where is the array for teleporting players ?

1 Like

is player is inside playeractivatedtouchtp

im not sure I got it right btw