local seatcheck = {}
local availableseats = {}
local takenseats = {}
local done = true
function seatcheck.seatchecker()
if done then
done = false
local seatfolder = game.Workspace:WaitForChild("seats") -- Waits for seats folder
for i, seat in ipairs(seatfolder:GetChildren()) do
if seat:IsA("Seat") then -- Make sure it's actually a seat
if seat.Occupant == nil then
if table.find(availableseats, seat.Name) then
else
table.insert(availableseats, seat)
end
else
if table.find(takenseats, seat.Name) then
else
table.insert(takenseats, seat)
end
end
end
end
done = true -- Set done to true after everything is complete
end
end
function seatcheck.getmeAseat()
if #availableseats == 0 then
warn("No available seats.")
return nil -- Return nil if no seats are available
end
local takingAseat = availableseats[math.random(1, #availableseats)]
availableseats[takingAseat] = nil
table.insert(takenseats, takingAseat)
return takingAseat
end
return seatcheck
this script is off a simple restaurant game, but something adds duplicates into the availabeSeats table. iām going to lose my mind pls help