How to loop through all the chairs when starting at a random chair?

So I have a bunch of chairs:

I’m trying to do something where the game starts by pointing to a random chair, finding that player, and then moving on to the next chair down the list. Players initially are all placed into these seats.

So, in logic (using the picture above):

  1. Find a random player.
  2. Get that player’s seat.
  3. Find the next seat after it (so, if it found a random player in Nano_Chair_03, it would check Nano_Chair_04 to see if that seat has a player.
  4. Continue until you have checked every single chair (so, Nano_Chair_03Nano_Chair_04Nano_Chair_05Nano_Chair_06Nano_Chair_07Nano_Chair_01Nano_Chair_02)

I’m not quite sure how to implement this.

Check with values for detecting players, and with for loops:

local seats = {}

for index, seat in ipairs(workspace.Objects.Chairs:GetDescendants()) do
if seat:IsA("Seat") then
table.insert(seat,indexl
end
end

for index=1, #seats, 1 do
print("Index at "..index
end

Sorry for bad formatting. Loops.

1 Like