I try to make the npc (the virus character) follow the player, but the problem is the npc runs into walls when the player turns a corner. I’ve tried using Humanoid.MoveToFinished:Wait()
but it still doesn’t seem to work.
game.ReplicatedStorage.RoomNumber.Changed:Connect(function(new)
if new == range1.Min + 1 then
virus.HumanoidRootPart.Anchored = false
spawn(function()
while game.ReplicatedStorage.RoomNumber.Value < range1.Max do
local path = game.PathfindingService:CreatePath(agentParams)
local character = game.Players:FindFirstChildWhichIsA("Player").Character
path:ComputeAsync(virus.PrimaryPart.Position, character.PrimaryPart.Position)
--if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
virus.Humanoid:MoveTo(waypoint.Position)
end
--end
task.wait()
end
end)
end
end)