Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to teleport all players to back-to-back?

Asked by 3 years ago

Hello, i need an system teleports all players to back to back, different parts. In game, we need to teleport different areas. Think an 2 teams. There are 6 players at each team. But players mustn't be teleported same part. They need to teleport back to back. Im trying to make this system, but i don't know how to make it, im new at coding. Can you help me? I need to use ipairs?

I have an screenshot you can look here if u didn't understand:

https://prnt.sc/11peezr

I want to teleport players at this parts (For photo)^^

Thanks, Uygi1234

1 answer

Log in to vote
0
Answered by 3 years ago

The function that I believe you are looking for is GetPlayers(), from the Players service. This function returns an array of players that are currently connected to the server. There is also another thing I would like to clear up: You do not need to prefer ipairs(). It is understandable that ipairs() is made for arrays, but pairs() itself also works for arrays. If you have a personal preference, so be it. I will not stop you.

Here is an iteration example of GetPlayers():

local plrs = game:GetService("Players"):GetPlayers()
for i, player in pairs(plrs) do
    print(player.Name)
end

Because this is an array, you can also achieve this using a numerical for loop if desired:

local plrs = game:GetService("Players"):GetPlayers()
for i = 1, #plrs do
    print(plrs[i].Name)
end

Notice how the generic loop is more straightforward. Arrays start at 1 in Lua and the value within the index is not immediately clear. As player would refer to the player in the current iteration i in the pairs() iterator function, plrs[i] also refers to the player in the current iteration i but it is not nearly as straightforward as player because player directly refers to the value the iteration hits, but plrs[i] refers to the value under index i.

0
does game:GetService("Players"):GetChildren() works same as :GetPlayers()? Xapelize 2658 — 3y
0
Not all of the time. GetChildren() returns every Instance under the object it is called from. GetPlayers() explicitly returns players under the Players service. DeceptiveCaster 3761 — 3y
0
Tsym, i'll try that im not sure how i can make this but i think ican make this. Thanks for your answer. You opened new way for me. Uygi1234 0 — 3y
Ad

Answer this question