NPC's sometimes not sitting in seat?

So my npc’s use pathfinding to get to a seat position, but sometimes they will not sit in the seat? Anyway to fix this?

Hm, not sure. Can you show me the position of where they are pathfinding and I can see why one gets on and one doesn’t get on.

their pathfimmding works perfectly, but since I got the pathfinding off the devforum and tweaked it, I was trying to look for a way to make them sit in the seat once its finished, but I couldn’t.

I had the same issue and the solution was to call the humanoid sit method when they were x distance

1 Like

Alright, ill see if I can put something together

I put this together, but it continues to run after they sit, anyway to stop it once their there, and if they move away restart it?

local char = script.Parent
local part = game.Workspace:FindFirstChild(script.Parent.SeatPart.Value)

while wait(1) do
	if (char.HumanoidRootPart.Position - part.Position).magnitude <= 3 then
		part:Sit(char:FindFirstChild("Humanoid"))
		print("char sat")
	end
end

In my code I had a array for each seat which stored another array for each index. It would store a boolean and the humanoid in the seat. So if they sitted in it the boolean would turn true and the nil index would be replaced with the humanoid sitting in it. I then used that array as reference in my game loop. To get them off im pretty sure you just remove the occupant weld then you shift their position a bit

1 Like

I tested this, and it seems to work decently? Wouldn’t know if it fully worked until I fully setup the system where they go back to their original position.

local char = script.Parent
local part = game.Workspace:FindFirstChild(script.Parent.SeatPart.Value)
dog = false

while wait(1) do
	if (char.HumanoidRootPart.Position - part.Position).magnitude <= 3 and dog == false then
		dog = true
		part:Sit(char:FindFirstChild("Humanoid"))
		print("char sat")
	else
		if (char.HumanoidRootPart.Position - part.Position).magnitude >= 3 then
			dog = false
			print("char not sat")	
	end
	end
	end

To stop it you need to add a break

while wait(1) do
	if (char.HumanoidRootPart.Position - part.Position).magnitude <= 3 then
		part:Sit(char:FindFirstChild("Humanoid"))
		print("char sat")
        break
	end
end

To restart it, it would probably be a good idea to make it a function then call the function each time they start moving again.

I think you should do what I said in creating a state machine ylsystem for the npcs

Basically, im trying to make a NPC food system, as a job where npc’s come in, you take their order, and then they get teleported back to their starting position and get put back in replicatedstorage afterward, but I haven’t set that up yet

Well if the objectvalue is already located, why you still need to find in the workspace again?

Have you managed to get it working? I would like to know how you managed to get them to pathfinder towards a specific seat!

Someone had the same problem but without the pathfinding service, I’ve helped him with this.

local NPC = script.Parent --NPC'S CHARACTER
local Seats = script.Parent.Parent:WaitForChild("Seats") --SEATS
local humanoid = script.Parent.Humanoid --HUMANOID OF NPC
wait(5)

for _, Seat in pairs(Seats:GetChildren()) do --GETS ALL SEATS
    if not Seat.Occupant then --IF SEAT ISN'T OCCUPIED
        humanoid:MoveTo(Seat.Position) --You can basically do this with pathfinding service
        humanoid.MoveToFinished:Wait() --Wait till pathfindingservice is done
        humanoid.RootPart.CFrame = Seat.CFrame + Vector3.new(0, humanoid.HipHeight + 1, 0) --then teleport the NPC to the seat
        Seat:Sit(humanoid) --Seat the NPC
    end
end

Since you’re using pathfinding services you can do this:

local PathfindingService = game:GetService("PathfindingService")
local NPC = script.Parent
local Seats = script.Parent.Parent:WaitForChild("Seats")
local humanoid = script.Parent.Humanoid
wait(5)

for _, Seat in pairs(Seats:GetChildren()) do
	if not Seat.Occupant then
			local path = PathfindingService:CreatePath()

			path:ComputeAsync(dummy.HumanoidRootPart.Position, finish.Position)-- computing

			local waypoints = path:GetWaypoints() -- waypoints variable


			for i = 1, 5 do
				if i <= #waypoints then
					if waypoints[i].Action == Enum.PathWaypointAction.Jump then
						humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
					end
					humanoid:MoveTo(waypoints[i].Position)
					humanoid.MoveToFinished:Wait()
				end
			end
		humanoid.RootPart.CFrame = Seat.CFrame + Vector3.new(0, humanoid.HipHeight + 1, 0)
		Seat:Sit(humanoid)
	end
end

I’ve no idea if this works, I haven’t tested it yet but it should look like this:

1 Like

Oops, you need to change line 11 to

path:ComputeAsync(NPC.HumanoidRootPart.Position, Seat.Position)

3 years later and this helped me, thank you!