Ai pathfinding open door the wrong way again

Repost*

  1. What do you want to achieve? Continue this post
    https://devforum.roblox.com/t/ai-pathfinding-open-door-the-wrong-way/2640788

  2. What is the issue? I open all door in house, but My ai pathfinding open the wrog way again, Here this video :Sory for my video solution:

  3. What solutions have you tried so far? I tried to rewhrite but every is same

Here the code in npc model

script

local plrs = game:GetService("Players")
local runs = game:GetService("RunService")
local pfs = game:GetService("PathfindingService")
local ts = game:GetService("TweenService")
local collectSS = game:GetService("CollectionService")

local NPC = script.Parent
local Humanoid = NPC.Humanoids
local HumanoidRootPart = NPC:WaitForChild("HumanoidRootPart")
local BodyColor = NPC:WaitForChild("Body Colors")

repeat
	task.wait()
until workspace:FindFirstChild("Monster")

local OriginalSpeed = Humanoid.WalkSpeed

local openSound = script:WaitForChild("Open"):Clone()
local openKnobSound = script:WaitForChild("OpenKnob"):Clone()
local closeSound = script:WaitForChild("Close"):Clone()

openSound.Parent = HumanoidRootPart
openKnobSound.Parent = HumanoidRootPart
closeSound.Parent = HumanoidRootPart

local ColorTables = {
	[1] = {
		["Color"] = BrickColor.Red(),
	},
	[2] = {
		["Color"] = BrickColor.Green(),
	},
	[3] = {
		["Color"] = BrickColor.Blue(),
	}
}

local function betterWait(number)
	local delta = 0
	
	while delta < number do
		delta += runs.Heartbeat:Wait()
	end
	
	return delta
end

function Play_Sound(id, parent)
	local sound = Instance.new("Sound", parent)
	sound.SoundId = id
	sound.PlayOnRemove = true
	game:GetService("Debris"):AddItem(sound, sound.TimeLength)
end

local rnd = Random.new()
local pickColor = ColorTables[rnd:NextInteger(1, #ColorTables)]
BodyColor.TorsoColor = pickColor.Color

--NPC open door
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = {HumanoidRootPart}
params.IgnoreWater = true

local DoorTable = {}
for _, model in pairs(collectSS:GetTagged("Door")) do
	local hingeDoor = model:WaitForChild("Hinge")
	DoorTable[hingeDoor] = hingeDoor.CFrame
end

while betterWait(0.5) do
	local direction
	for _, model in pairs(collectSS:GetTagged("Door")) do
		direction = model.TriggeredPart.Position - HumanoidRootPart.Position
	end

	local raycast = workspace:Raycast(HumanoidRootPart.Position, direction, params)

	if raycast then
		local obj = raycast.Instance
		if obj then
			for _, model in pairs(collectSS:GetTagged("Door")) do
				local open = model.IsOpenned
				local db = false
				
				local hingeDoor = model:WaitForChild("Hinge")
				local Door = model:WaitForChild("Door")
				local Door_knob_In = model:WaitForChild("Door_knob_In")
				local Door_knob_Out = model:WaitForChild("Door_knob_Out")
				local TriggeredPart = model:WaitForChild("TriggeredPart")

				local currentCFrame = hingeDoor.CFrame
				
				local goal
				local tsInfo = TweenInfo.new(
					1,
					Enum.EasingStyle.Linear,
					Enum.EasingDirection.Out
				)

				if (raycast.Position - TriggeredPart.Position).Magnitude < 5 then
					if not db then
						db = true
						Humanoid.WalkSpeed = 0
						if not open.Value then
							open.Value = true
							Play_Sound("rbxassetid://8313170560", hingeDoor)
							Play_Sound("rbxassetid://5037969255", hingeDoor)
							goal = {CFrame = DoorTable[hingeDoor] * CFrame.Angles(0, math.rad(90), 0)}
							Door.CanCollide = false
							Door_knob_In.CanCollide = false
							Door_knob_Out.CanCollide = false
						else
							open.Value = false
							Play_Sound("rbxassetid://7038967181", hingeDoor)
							goal = {CFrame = DoorTable[hingeDoor]}
							Door.CanCollide = true
							Door_knob_In.CanCollide = true
							Door_knob_Out.CanCollide = true
						end

						local tween = ts:Create(hingeDoor, tsInfo, goal)
						tween:Play()
						tween.Completed:Wait()
						Humanoid.WalkSpeed = OriginalSpeed
						db = false
					end
				else
					--Bug >:(
					Humanoid.WalkSpeed = OriginalSpeed
				end
			end
		end
	end
end

I trie everytime to rewrite a code of my npc ai pathfinding but i open all door in house but door has open the wrong way, i don’t know how to fix it