How do I grab a group of people's, players?

I’ll make this quick, I am trying to make a teleporter like, Survivor. Where you touch it and after 30 seconds, it teleports the group of players. I know about :TeleportToPartyAsync but how would I grab a group of people’s player?

2 Likes

I’d take an OOP (Object-Oriented) approach and instance a team as a table. Add the player to the table to signify a party. You can append the player instances of whoever and use that as your players object.

Hope this helps!

That is not an OOP approach. I recommend learning what terminology actually means before tossing it around to confuse people. An OOP approach would be a class based structure with constructors and inheritance, not just using a table.

4 Likes

Can you make it more simple? Sorry, just started to use :TeleportToPartyAsync

Just store all the players you want to teleport into a table and then when you want to teleport them iterate through the objects of the table and teleport each player inside the table to the desired location.

All objects in Lua are ultimately tables. Perhaps, you shouldn’t attack a person publicly. : )

I wasn’t trying to attack you, I was just trying to avoid any misconceptions on what OOP is. While OOP is implemented in Lua through tables, OOP specifically refers to the use of class-like objects created with tables. Sorry if the tone came off badly through my original post.

2 Likes

Is there a way without doing tables or such?

Considering one of the party teleport function’s arguments is a table, you can’t really avoid using them.

2 Likes

If you’re not really sure how tables work, you can read the tables article in the developer hub.

I meant, about getting the group of players.

A table is how you store multiple values. Storing multiple players would definitely need a table. Like Colvy said, you can always check the wiki if you’re not very confident with tables.

2 Likes

First, we’ll need to find a way to fetch the players who are inside of the teleporting pad. Personally, I’d recommend using an invisible box above your desired teleporting pad, and use the GetTouchingParts() function to get a table of all of the instances that are within the collision bounds of the box. Then, we can call the function every x seconds to check if anyone has joined or left the teleporting pad.

When we get a table of all the instances, we will then need to filter out any unnecessary parts, and look for something like a HumanoidRootPart, where we can easily find the Player instance. Then, we store them inside of a more refined table, then send them on their merry way.

Here’s some sample code:


local TELEPORTING_BOX = workspace.TeleportBox
local UPDATE_INTERVAL = 1 --frequency at which it will update

local UPDATE = coroutine.wrap(function()
    while true do
        local PLAYERS_TO_TELEPORT = {} --a table where all connected players will be
        local TOUCHING_PARTS = TELEPORTING_BOX:GetTouchingParts()
        for _,INSTANCE in ipairs(TOUCHING_PARTS) do
            if INSTANCE.Name == "HumanoidRootPart" then
                local DETECTED_PLAYER = game:GetService("Players"):GetPlayerFromCharacter(INSTANCE.Parent)
                if not PLAYERS_TO_TELEPORT[DETECTED_PLAYER] then
                    table.insert(PLAYERS_TO_TELEPORT,#PLAYERS_TO_TELEPORT,DETECTED_PLAYER)
                end
            end
        end
        game:GetService("TeleportService"):TeleportPartyAsync(--place id,PLAYERS_TO_TELEPORT)
        wait(UPDATE_INTERVAL)
    end
end

UPDATE()

Hope this helped! :smiley:

2 Likes

Thank you! It worked for me! :grinning:

1 Like

Cool thing.

local Rectangle = {}

Rectangle.new = function(lengthValue, widthValue)
	local object = {}
    self = object
	setmetatable(object,self)
	self.__index = self
	self.Length = lengthValue
	self.Width = widthValue

  self.area = function()
    self = object
    print("Length = ",self.Length)
    print("Width = ",self.Width)
    return (self.Length * self.Width)
  end

	return object
end

local rect_1 = Rectangle.new(5,2)
local rect_2 = Rectangle.new(1,7)
print("Rectangle_1: ",rect_1.Length,rect_1.Width, rect_1.area())
print("Rectangle_2: ",rect_2.Length,rect_2.Width,rect_2.area())