How do I go about a party system?

In some games, namely Prison Royale by ScriptOn, there is a so-called party system. It means that when there is a lobby for a set game, several players can stand within a model or set area, and it will instantly teleport them to a server together if the counter is met with enough players or a certain time passes.

I know fairly well from the Wiki how to teleport players together, but cannot seem to find a good place to start. Do I determine whether enough players have touched the brick and are standing within a certain range of it, and then grab their UserIDS for teleport, or do I first grab the UserIDS, and only then teleport, as long as they are still within the range of that given brick?

As I am not the most advanced person when it comes to these kinds of features in games, I would really appreciate some tips and helpful links. :slightly_smiling_face:

5 Likes

So, I think you should first check to see if enough players are on the brick (if I am understanding what you are trying to accomplish).
to do that, you could try using the GetTouchingParts function. Personally, I have never used it, but I am getting information on it, and think I understand. So maybe do something like this:

local Part = script.Parent
script.Parent.Touched:Connect(function(hit)
local tableOfParts = Part:GetTouchingParts()
local numberOfPlayers = 0
for i,v in pairs(tableofParts) do
if v:FindFirstChild(“Humanoid”) then
numberOfPlayers = numberOfPlayers + 1
end
end
if numberOfPlayers == NUMBEROFREQUIREDPLAYERS then
for i,v in pairs(tableOfParts) do
if v:FindFirstChild(“Humanoid”) then
local plr = game:GetService(“Players”):GetPlayerFromCharacter(v)
game:GetService(“TeleportService”):Teleport(PLACEID,plr)
end
end
end
end)

I am not sure if that is what you are looking for, or if that is correct. Apologies for any inconveniences or incorrectness.
Hope this helps.

7 Likes

Hey rooboo14!

Yeah, this actually helps a lot. I didn’t know how to go about controlling the amount of players that are teleported all together, you understood me correctly.

I think this is a great place to start. I appreciate your help, it’s much less confusing now.

Very glad I was able to assist! I hope your game turns out to be amazing! Have a lovely day. :slight_smile:

1 Like

Hey @Flamingles!
While the general idea of the above script is correct, it will not work correctly since the Humanoid is stored inside the character model, not inside one of the character’s parts. It will also trigger a lot more than it needs to with players walking around on the part.

I’ve written some code which will detect players above a part which you specify:
Screenshot of the code with correct formatting:

Actual code:

local TeleportPart = workspace.Part – The teleport part
local MaxPlayers = 10 – How many players should the teleport wait for?

local function TeleportPlayers(PlayerTable)
for _,Player in pairs (PlayerTable) do
print(Player, “is ready to be teleported!”)
– Teleport the player
end
end

local function WaitForPlayers()
while wait(1) do
local PlayersOnTeleportPart = {} – Make a new table for the players
for _,Player in pairs (game.Players:GetPlayers()) do – Get all the players
if Player.Character and Player.Character:FindFirstChild(“HumanoidRootPart”) then – Do they have a character and a HumanoidRootPart?
local CharPos = TeleportPart.CFrame:PointToObjectSpace(Player.Character.HumanoidRootPart.Position) – Convert their HRP position to a local position, relevant to the teleport part.
if math.abs(CharPos.X) < TeleportPart.Size.X/2 and math.abs(CharPos.Z) < TeleportPart.Size.Z/2 then – Is the local position inside the size of the teleport part?
table.insert(PlayersOnTeleportPart, Player) – If yes, add them to the table.
end
end
end

  print(#PlayersOnTeleportPart) -- Debugging to check that it works
  
  if #PlayersOnTeleportPart >= MaxPlayers then -- Do we have enough players?
  	TeleportPlayers(PlayersOnTeleportPart) -- Yes, let's call the teleport function
  	break -- We don't need the loop anymore
  end

end
end

WaitForPlayers()

9 Likes

Hey Algy.

I appreciate this one a lot. I was specifically looking for something that uses math and multiple tables to make this work, hence why I had a bit of trouble making it myself. It works just fine with what I was trying to do!

I’ll go about closing this topic now, I understand what i’m doing. Thanks to both of you!

1 Like