NPC Pathfinding not working; NPC doesn't move at all

Hello, I am having an issue with my NPC pathfinding. I am currently trying to get my NPC to walk into his house during the night, and walk out of the house during the day. However, whenever I go to test, the NPC does not move at all except for when the random move script is active. The random move script makes the NPC walk around randomly, however, I make sure to disable the script when it is time for the NPC to walk into his house. Here is my code, a script located inside of the NPC:

-- services 

local RunService = game:GetService("RunService")
local PathfindingService = game:GetService("PathfindingService")

-- stuffs

local Move = script.Parent.Move -- script inside npc that makes him walk randomly
local Humanoid = script.Parent:FindFirstChild("Humanoid")
local Root = script.Parent:FindFirstChild("HumanoidRootPart")
local Goal1 = game.Workspace.ClassicHouse.Goal1 -- inside of the house
local Goal2 = game.Workspace.ClassicHouse.Goal2 -- outside of the house

-- paths

local path1 = PathfindingService:CreatePath()
local path2 = PathfindingService:CreatePath()

path1:ComputeAsync(Root.Position, Goal1.Position)
path2:ComputeAsync(Root.Position, Goal2.Position)

-- waypoints

local waypoints1 = path1:GetWaypoints()
local waypoints2 = path2:GetWaypoints()

-- debounce

local IsInside = false

-- functions

local function GoInside()
		if not IsInside then
			Move.Enabled = false
			for _, waypoint in pairs(waypoints1) do
				Humanoid:MoveTo(waypoint.Position)
				Humanoid.MoveToFinished:Wait()
			end
		IsInside = true 
	end
end

local function GoOutside()
	if IsInside then
		for _, waypoint in pairs(waypoints2) do
			Humanoid:MoveTo(waypoint.Position)
			Humanoid.MoveToFinished:Wait()
		end
		Move.Enabled = true
		IsInside = false
	end
end

-- connect

RunService.Heartbeat:Connect(function()
	game:GetService('Lighting'):GetPropertyChangedSignal('ClockTime'):Connect(function()
		local CurrentTime = game.Lighting.ClockTime
		if CurrentTime > 18 then
			GoInside()
		elseif CurrentTime < 6 then
			GoOutside()
		end
	end)
end)

Basically, NPC will not pathfind at specific time of day. Any help would be much appreciated!

3 Likes

are you sure GoInside or GoOutside did trigger?

1 Like