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)
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?
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?
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.
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.
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