Firing all Clients in a table

Hey there! Sorry for asking so many questions today, this will most likely be my last, but anyways, onto the question.

So I’m trying to recreate my system for my game, Alone, in the lobby place. I wanted to make a system where when a player joins, they automatically get added to a table called ‘playerList’. When the game reaches 2 players (will be changed to 10 on release), it fires every client in that table, but how can I fire to every player in that table? Script is below! Thanks!

local playerList = {}
game.Players.PlayerAdded:Connect(function(player)
if #playerList < 10 then
table.insert(playerList, #game.Players:GetPlayers(), player)
end
end)
repeat wait() until #playerList == 2
game.ReplicatedStorage.TeleportToNewPlace:FireClient(playerList)

Thanks again, it means a lot! :slight_smile:

If playerList is a array of all the players you want to fire, then all you have to do is loop through those players and fire them individually in the same loop:

for _, plr in pairs(playerList) do 
    game.ReplicatedStorage.TeleportToNewPlace:FireClient(plr)
end

Also note that you can teleport a group of players from the server:

teleportSevice:TeleportPartyAsync(gameid, playerList)
1 Like

Oh, alright, I understand that, OK, thanks so much! :slight_smile:

Glad you understood it. Just remember you can teleport from the server a group of players if you want to do it that way also. Both ways will work, it’s ultimately your choice. Glad I could help.

1 Like

Yup, so one thing I should tell you is, the reason I’m not going to use the Party method in this instance because there’s a GUI that pops up, loads every player’s values before teleporting, then teleports to the game map. So that’s the only reason, but thanks for telling me that! I will DEFINITELY use that later!

Oh, in that case it’s fine. I always like to check just because there is a wide range of understanding on this forum, so sorry if I annoyed you. Have a good day.

1 Like

Oh no, thats fine, you just taught me an extra feature, not annoyed me lol! :stuck_out_tongue:

1 Like