So I have 4 seats. When I run a program, I want that if there are any players in the seats (1, 2, 3 or 4, all of them occupied) then I want to enable a value inside the occupied seat. Currently I am checking the stuff like this:
if seat1.Value.Value == true and seat2.Value.Value == true and seat3.Value.Value == true and seat4.Value.Value == true then
print("No seats free")
else
print("A seat is free")
end
But doesn’t quite work and it’s messy. What should I change this to?
You could assign all of the seats to a table, and then do an in-pairs function to check for congruency.
local seats = {
seat1,
seat2,
seat3,
seat4
}
local function CheckSeatStatus()
for _,seat in pairs(seats) do
local vacant = {}
local occupied = {}
if seat.Occupant or seat.Occupied.Value then -- Occupied being the name of the bool value stored inside the seat.
print(seat.Name.." is occupied!")
table.insert(occupied, seat)
else
print(seat.Name.." is vacant!")
table.insert(vacant, seat)
end
return vacant, occupied
end
end
local vacant, occupied = CheckSeatStatus()
if #vacant == 0 then
print("All seats taken!")
end