TeleportService:TeleportPartyAsync isn't working

  • What are you attempting to achieve? (Keep it simple and clear) - I’m trying to achieve where my party teleports to a different game if it meets the requirements of the minPlayerCount and if it looks for how many people are in the PlayerCountTable

  • What is the issue? - Not too sure but TeleportService:TeleportPartyAsync does not work I’m pretty sure I have it correctly written.

  • What solutions have you tried so far? - I’ve searched on the DevForums.

local InvisFloor = script.Parent.BoatMesh.Floor
local PlayerCountTable = {}
local TeleportService = game:GetService("TeleportService")
local gameID = 3149170638
minPlayerCount = 1

function OnTouch(hit)
	local character
	local player
	if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") then
		character = hit.Parent
		player = game:GetService("Players"):GetPlayerFromCharacter(character)
		if not player then
			return
		else
			table.insert(PlayerCountTable, player)
		end
	else
		return
	end
end

	if #PlayerCountTable >= minPlayerCount then
		TeleportService:TeleportPartyAsync(gameID, PlayerCountTable)
end

InvisFloor.Touched:Connect(OnTouch)
2 Likes

Does the output display anything?

1 Like

Nothing coming from the output whatsoever.

TeleportPartyAsync is meant to teleport to a place in the same game, not a different game.

Read the Roblox Wiki article before asking questions please.

Teleport Party Async-Developer Hub

You may only use this function to teleport to a place in the same game. This function can not teleport more than 50 Players in a single party.

If game id is a place id (variable name is badly named), then ignore the above.

1 Like

What do you mean lol, the place is in the same game I am using the correct terminology.

You called your place id game id. I thought that it was a game id.

Moving on, add a print statement inside your if then. See if it prints.

print(#PlayerCountTable)
if #PlayerCountTable >= minPlayerCount then
print(1)
TeleportService:TeleportPartyAsync(gameID, PlayerCountTable)
end

He was just trying to help (although it doesn’t mean much since it was a nitpick of variable naming), no need to put up a rude tone. As far as terminology goes though, before I answer your question, there’s actually a difference. “Game” is what places are commonly referred to as. Places make up a game and each place has instances (what are commonly called servers). The terms are just different so you can refer to them more easily.

Common Proper
Server Instance
Game Place
Universe Game

Anyway, your code doesn’t look wrong so the first assumption I want to make, without testing this code myself, is that the PlayerCountTable is blank. Have you tried iterating through it to see if there are indeed players in that table?

I’m sorry. I didn’t mean to come off in such tone. I could indeed create a print to see if a player is added to the table to make sure that it works.

That was weird, it printed 0 instead of 1

That means that the array is blank. The player is not inserted. At some point, your touched function fails.

Try adding prints to that function.

function OnTouch(hit)
print(hit:GetFullName())
	local character
	local player
	if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") then
		character = hit.Parent
		player = game:GetService("Players"):GetPlayerFromCharacter(character)
print(player)
		if not player then
			return
		else
			table.insert(PlayerCountTable, player)
		end
	else
		return
	end
end

Is the part anchored? Does it fall through the floor? Is the part defined correctly?

Your code is showing your call to TeleportPartyAsync directly after the definition of OnTouch and right before you connect the function to Touched. This means that before the function is connected to Touched and players can be added to PlayerCountTable , you are prematurely attempting to teleport the players.

When you are intending for the teleport to happen? Once the minimum player count is reached?

When you are intending for the teleport to happen? - Yeah I’m intending it to happen once the minimum playercount has been reached.

The part is anchored, It is defined.

You are figuring out whether to teleport on the startup, before the player touches the platform. Try this:
Loops every 10 seconds to check.

while true do
if #PlayerCountTable >= minPlayerCount then
		TeleportService:TeleportPartyAsync(gameID, PlayerCountTable)
end
wait(10)
end

Yeah I’m intending it to happen once the minimum playercount has been reached.

Then you need to make this check every time the PlayerCountTable is updated. The easiest way to do this would be to define a second function like so:

function TableRefreshed()
    if #PlayerCountTable >= minPlayerCount then
	TeleportService:TeleportPartyAsync(gameID, PlayerCountTable)
    end
end

And then call this function whenever you update the table.

You also need to keep in mind that with your current code a player can be added to the table multiple times. I don’t know if this would cause issues with TeleportPartyAsync, but it is probably not intended.

Replied to the wrong person, my bad.

Adding on to that, you may want to wait depending if you want more players than the minimum.

We all make mistakes, no worries @goro7

To be honest, the OP should have some kind of icon

1 Like

I still cannot get this to work, I have literally tried doing everything such as checks to see if a player has been added to the table, it returns still as 0, I don’t know any other possible way of it working.

UPDATE

Basically I changed the code around. And I thought I had it but it still doesn’t give me an error and it doesn’t teleport.

local InvisFloor = script.Parent.BoatMesh.Floor
local PlayerCountTable = {}
local TeleportService = game:GetService("TeleportService")
local placeId = 3149170638
local minPlayerCount = 1
local character
local player

function OnTouch(hit)
	if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") then
		character = hit.Parent
		player = game:GetService("Players"):GetPlayerFromCharacter(character)
		if not player then
			return
		else
			table.insert(PlayerCountTable, player)
			if #PlayerCountTable >= minPlayerCount then
			TeleportService:TeleportPartyAsync(placeId, #PlayerCountTable)
			end
		end
	end
end

InvisFloor.Touched:Connect(OnTouch)

I really appreciate all of the help.

Okay, I just got an error of

TeleportService:TeleportPartyAsync error: The player[901149570] with wrong session

Have you tried to teleport the one player without using a table?
This is so you can eliminate that part of the code.

You are teleporting the number 1. 1 is a number and not a table. Remove the # from #PlayerCountTable.

if #PlayerCountTable >= minPlayerCount then 
TeleportService:TeleportPartyAsync(placeId, PlayerCountTable)
 end
2 Likes