How do I force an npc to go to the nearest seat?

The problem is the seats are in models so is there a way I can search through every single model in a folder that has a seat and move the npc to the seat?

1 Like

You would need a way to determine which seat (once you’ve found all the seats) you want the npc to move to, but for moving the npc, assuming it’s a normal R6 humanoid body, you could do something like this;

local NPC = [Insert NPC model path]

function MoveToSeat(NPC : Model, Seat : Seat)
  if not NPC or not Seat and Seat:IsA('Seat') then
    error('Failed to provide parameters for NPC moving function', 1);  do return end
  end
  local Humanoid = NPC:FindFirstChildWhichIsA('Humanoid')
  
  if not Humanoid then return else
    Humanoid:MoveTo(Seat.Position)
    Humanoid.MoveToFinished:Wait()
    wait(.05)
    if not Humanoid.Sit then
      Seat:Sit(Humanoid)
    end
  end
end

Of course it would be best to do incorporate pathfinding into this, prevent MoveToFinished timeout or add a way to prevent it from accidently sitting in other seats on it’s way to the designated seat but that’s for you to figure out since I don’t wanna spend time on this, goodluck man!