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