Teleporttoprivateserver doesnt work, yet again

hey! so i was bored and i wanted to make a tower defense because why not
i was trying to do the teleport system thingy and i have no clue why it doesnt work since i very rarely use teleportservice and all of that

this is my code: (please d ont judge)

local TeleportService = game:GetService("TeleportService")

local part1 = workspace.Part1
local part2 = workspace.Part2
local part3 = workspace.Part3

local players1 = {}
local players2 = {}
local players3 = {}

function teleportPlayers(players : {})
	for _,player : Player in players do
		if player.Character then
			player.Character:Destroy()
		end
	end
	local code = TeleportService:ReserveServer(114926659199460)
	for i = 1, 5 do
		print("trying to tp")
		local success, err = pcall(function()
			TeleportService:TeleportToPrivateServer(114926659199460, code, players)
		end)
		task.wait(3)
		if success then
			print("teleported")
			break
		else
			warn(err)
		end
	end
	for _,player : Player in players do
		player:Kick("Failed to teleport :(")
	end
end

task.spawn(function()
while wait(0.1) do
	table.clear(players1)
	for _,part in workspace:GetPartsInPart(part1) do
		if part.Name == "HumanoidRootPart" then
			table.insert(players1, game.Players:GetPlayerFromCharacter(part.Parent))
		end
	end
	part1.Billboard.Players.Text = `{#players1} Players`
	table.clear(players2)
	for _,part in workspace:GetPartsInPart(part2) do
		if part.Name == "HumanoidRootPart" then
			table.insert(players2, game.Players:GetPlayerFromCharacter(part.Parent))
		end
	end
	part2.Billboard.Players.Text = `{#players2} Players`
	table.clear(players3)
	for _,part in workspace:GetPartsInPart(part3) do
		if part.Name == "HumanoidRootPart" then
			table.insert(players3, game.Players:GetPlayerFromCharacter(part.Parent))
		end
	end
	part3.Billboard.Players.Text = `{#players3} Players`

end		
end)

while true do
	for i = 10, 0, -1 do
		task.wait(1)
		part1.Billboard.Countdown.Text = i
		part2.Billboard.Countdown.Text = i
		part3.Billboard.Countdown.Text = i
	end
	part1.Billboard.Countdown.Text = "Teleporting..."
	part2.Billboard.Countdown.Text = "Teleporting..."
	part3.Billboard.Countdown.Text = "Teleporting..."
	if #players1 > 0  then
		task.spawn(function()
			teleportPlayers(players1)
		end)
	end
	if #players2 > 0  then
		task.spawn(function()
			teleportPlayers(players2)
		end)
	end
	if #players3 > 0  then
		task.spawn(function()
			teleportPlayers(players3)
		end)
	end

	task.wait(5)
end

and this is my console:

{30D1203E-2C73-4BCD-BA86-4FDBB87151C6}

(idk why the table says some random stuff but pretty sure theres no problem with that since my character gets deleted after the countdown is over)

1 Like

I’m not too familiar with TeleportService but from the looks of it, your script might work if you use an array instead of a number for the first parameter of the TeleportToPrivateServer method. The argument would look like this: {114926659199460} instead.

*Note you might have to change the same thing with other areas that you use the Id in.

looks like it did not change anything :pensive:

I think 114926659199460 is not an UserId, but rather a private server Id (didn’t know that) after reading the docs

Nevermind, I looked at the TeleportService documentation and that is not true; you did it correctly. I’ll look into it some more.

2 Likes

that was actually the place id!

here are the arguments in order

1 Like

Didn’t know PIDs could be so long, oh wow. Well, after roblox’s asset enumeration update, I guess I ain’t really that surprised.

Are you in Roblox Studio? I am pretty sure that you can’t teleport when you’re testing in studio. I’ve reviewed your script briefly and there doesn’t seem to be anything detrimental , so that is a possibility

1 Like

no i was in a real game it still didnt work

ok so i fixed it by looping all the players and teleporting them one by one (no clue why that fixed it)
if anyone could tell me what i did wrong it would be appericiated

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.