Seat order via number?

So, I haven’t found a solution by searching (or maybe I don’t know the keywords to what to search?) however, what I’m basically trying do is a sort of “queue” system of seats.

Example:


The seats are numbered from 1 - MaxNumber.

The script will check the seats, if it finds no player in seat 1, it will sit a player down.

However, if a player is occupying seat 1 already and it checks, then the player will go to seat 2.

However again, if a player leaves seat 1, it becomes unoccupied however, player 2 will still stay in seat 2 unless they re-join the queue.

A player can join and the script will check, if the script sees that theres no player in seat 1 of course, it will set the player into seat 1.

The script will keep going until the time limit is up or all seats are filled. Tried wrapping my head around it a bit but it goes more confusing as I typed it out :sweat_smile: Pretty sure I’m overcomplicating this.

local seats = {}

-- currentPlayers is the current amount of players there are, its a number val.
-- seats has the result of the folder of seats:GetChildren(). Ex, seats[1]
for seatNum = 1, currentPlayers do
	rootpart.Anchored = true
	if seats[seatNum] == character then
		--?
	else
		seats[seatNum] = character
		rootpart.CFrame = seats[seatNum].CFrame
	end
end
1 Like

Try this:

local seats = {}

for seatNum = 1, currentPlayers do
  if not seats[seatNum].Occupant then
     seats[seatNum]:Sit(character.Humanoid)
  else
    if not seats[seatNum + 1].Occupant then
       seats[seatNum + 1]:Sit(Character.Humanoid)
    else
        seats[seatNum + 2]:Sit(Character.Humanoid)
    end
  end