Npc can’t get off seat!

So I have a npc walking to a seat (using pathfinding service) and that works I use humanoid:Sit() to sit the npc the seats are disabled, but every time the npc gets off the seat there’s a 50% chance
that it’ll do this

I have no idea how to fix this and I don’t think it’s the pathfinding but it might be that setting humanoid.Sit = false is breaking the npc and making pathfinding not work,
This function is in a module script that is called from the server

function module.CustomerServed(player, customer, hairChosed)
   local char = player.Character
   char:PivotTo(customer.HumanoidRootPart.CFrame * CFrame.new(0,0,2))

   task.wait(1.5)

   player.Coins.Value = giveCoins(player.Coins.Value)
   player.PlayerGui.Coins.CoinFrame.CoinCounter.Text = player.Coins.Value
   local hair = game.ReplicatedStorage.HairStyles:FindFirstChild(hairChosed)

   local hairClone = hair:Clone()

   print(customer.Name)

   hairClone.Parent = customer.Head
   hairClone.Handle1:WaitForChild("AccessoryWeld").Part1 = customer.Head

   task.wait(1)

   customer.Humanoid.Sit = false
   for_,anim in pairs(customer.Humanoid.Animator:GetPlayingAnimationTracks()) do
      if anim.Name == "SitAnim" then
         anim:Stop()
         break
      end
   end

   customer.HumanoidRootPart.Position = customer.HumanoidRootPart.Position + Vector3.new(0,0,-5)
   path(customer, workspace.SpawnLocation.Position)
   customer:Destroy()
end

If you know a better way to do sit = false on npcs then I would like to know

Are you destroying the Weld that is created automatically when the NPC sits? The weld is inside the Seat part.
The Humanoid of the NPC has a property called SeatPart, which points to the Seat part the Humanoid is sitting on. Access that part and delete the Weld

I saw a weld in the seat, but when it glitches the weld still disappears

if i was you i would just destroy the seat and replace it with a dif seat then make the npc jump.

It didn’t happen for a little bit longer, but it did the exact same thing after a minute

I missed this part, so you mean that Seat is actually disabled? So you are just setting the NPC into the Seat coordinates, anchor it and playing a sit animation?
If thats the case, then yeah, I guess the weld of the Seat has nothing related with the issue…

The pathfinding is not still running trying to reach the Seat?

I don’t know what you by anchor, but it’s not that going to the sit is problem it’s that it can’t walk out the building, the path very slowly makes waypoints for some reason

By anchor I mean, that I supposed you were anchoring the NPC RootPart so it stays correctly in its place while getting the haircut. Just that.

I know, what I meant, the pathfinding you used to lead the NPC to the Seat still running when you started a new pathfinding to make it leave the building? like stacking 2 pathfinding functions.

You are not showing the code you used to make the NPC walk to the Seat, thats why Im asking that

these are the functions above

local pathfindingService = game:GetService("PathfindingService")

local function path(rig, position)
	local path = pathfindingService:CreatePath({["AgentCanJump"] = false})
	path:ComputeAsync(rig.HumanoidRootPart.Position, position)
	rig.PrimaryPart:SetNetworkOwner(nil)
	while true do
		print("loop")
		if path.Status == Enum.PathStatus.Success then
			print("success")
			for _,waypoint in pairs(path:GetWaypoints()) do
				rig.Humanoid:MoveTo(waypoint.Position)
				print("move")
				rig.Humanoid.MoveToFinished:Wait()
				print("stop")
			end
			break
		else
			warn("No Path Found")
			break
		end
	end
	return path
end

function module.spawnCustomer(player, customer, slotOn)
	local slot = workspace:FindFirstChild("Slot"..tostring(slotOn))
	local seat1 = slot.Seat1
	local seat2 = slot.Seat2
	local seat3 = slot.Seat3
	local seatTable = {seat1,seat1,seat1,seat1,seat1,seat2,seat2,seat3}

	print("that")
	local seat = seatTable[math.random(1,#seatTable)]
	local customerClone = customer:Clone()
	customerClone.Name = "Customer1"
    customerClone.Parent = workspace:FindFirstChild(tostring(player.DisplayName).."'s Customers")
	for _,v in pairs(customerClone:GetChildren()) do
		if v:isA("BasePart") then
			v:SetNetworkOwner(nil)
		end
	end
	local hum = customerClone:WaitForChild("Humanoid")
	local sitAnim = customerClone.Animate.sit.SitAnim
	local sitAnimTrack = hum.Animator:LoadAnimation(sitAnim)
	task.wait(1)
	path(customerClone, seat.Position + Vector3.new(0,0,-5))
	print("any")
	seat:Sit(customerClone.Humanoid)
	sitAnimTrack:Play()
	player.CustomersWaiting.Value += 1
end

You are using Seat instances for the seats or just a normal part?
Are you totally sure all the Seats are disabled? If the NPC gets close enough to an active Seat, the NPC will sit automatically causing that the while loop that is controlling the pathfinding wont stop never, cause the Humanoid never reached the waypoint, so, when you stand up the NPC the previous pathfinding (trying to reach the seat) and the new pathfinding (leaving the building) will try to run at once.

I see this offset of -5 from the seat, but in the video I see the NPC is sitting exactly on the seat, so it looks like the seat is active, causing the issue I explained
path(customerClone, seat.Position + Vector3.new(0,0,-5))

Another clue about the Seat being active is that fact that you saw the Weld appear and disappear, that should not happen if the Seat is unactive. No welds should be created if the Seat is disabled

the seats are actual seats, there was some other seats somewhere else that were not disabled, I disabled it but it keeps creating a weld in the seat, also I did a print check and it does break out the while loop when the glitch happens

Ok, I understand, but how did you achieve to make the NPC sit exactly on the seat spot, if the pathfing waypoint is actually -5 studs offset from the seat?
image

I tested your code, and when the Seat is disabled no Welds are created, its not possible.

I tested it with an active Seat and yeah the loop wont break, I tested it with disabled seat and the NPC goes 5 studs away from the Seat, no welds created and the loop breaks correctly.

And if the Seat is disabled, and you make the Humanoid to sit down, it sits on the ground, cause its not Anchored (as I stated before). That NPC is actually sit on an active Seat, causing the loop to not break

the sit() makes characters sit even when sit is disabled, is it better to not use sit()? cause I made the npcs HumanoidRootPart anchored and it sat at the pathfinding offset, before it left I unanchored the HumanoidRootPart and it fell

Yeah, if you tell the Humanoid to sit down, it will sit no matter if there is an available Seat or not, usually those will simply sit on ground, changing it state to sit.

There is not a better or worse way, it just depends how you wanna handle it. By using the default Seat functions or just anchor the HRP of the NPC and play an animation without even needing to use Sit().
Or you can use enabled Seats, both will work, depends on what you prefer.

Thats the expected behaviour and will cause that the loop handling the pathfinding will stop, and thats exactly what you want. Cause if the NPC literally uses the Seat the pathfinding loop could stop or not (that 50% chances you were talking about of fail), causing the issue you’ve been experiencing.

Have you tried making some kind of debounce, so when the npc leaves the seat, it isn’t fored to sit. Because if you jump from the seat/leave it you’d still be touching the part. So adding a denounce on how the npc tuches the part could help maybe

That would be pointless, cause @Lexiplaysroblox_Lexi is using an approach that has the Seat disabled, so none default functions of the seat are running, no needing a debounce. But, I really think that some of those Seats are actually enabled by mistake, in which yeah a debounce would help to fix it

ok I’m going back to the sit() method, this is the output for the pathfinding function “move” means moving to waypoint “stopped” when move finished “stop walking” when pathfinding done

I don’t think it’s stopping the loop when it’s unanchored since it always prints “stop walking”

Maybe after you state “customer.Humanoid.Sit = false” you could move them a bit forward to avoid the blocking. I have scripts that do this and I like to use jump also, like idkyouknowl stated. Maybe a lerp or move to just in front of the seat after not sitting. I’m thinking the animation to walk away is blocked, resulting in shuddering the errors. Never really tried this with an NPC. Is there some anim that needs to be reset or restarted (the path finding) …

that’s what this is for

and for stopping the sitting animation