I’m currently having an issue as I’ve just started using pathfinding where my NPC is stuttering. I’ve looked up how to fix it like setnetworkowner(nil) but it doesn’t seem to work. I don’t know if there’s an issue with movetofinished or whatever. It’s also not smooth, and seems to find the path slowly. Here’s an example below
this is the code below
local function NPCScript()
local Target = nil
local studs = 200
for _, v in workspace:GetChildren() do
local HumanoidRootPart = v:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart and HumanoidRootPart ~= NPCHUmanoidRootPart and HumanoidRootPart ~= script.Parent and HumanoidRootPart:GetAttribute("OtherNPC") == false then
if (HumanoidRootPart.Position - NPCHUmanoidRootPart.Position).Magnitude < studs then
studs = (HumanoidRootPart.Position - NPCHUmanoidRootPart.Position).Magnitude
Target = HumanoidRootPart
end
end
end
return Target
end
local Path = PathFindingService:CreatePath({
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true,
AgentCanClimb = false,
WaypointSpacing = 4
})
for i, v in Rig:GetChildren() do
if v:IsA("BasePart") then
v:SetNetworkOwner(nil)
end
end
while true do
local HumanoidRootPart = NPCScript()
if HumanoidRootPart then
local Success, Unsuccessful = pcall(function()
Path:ComputeAsync(NPCHUmanoidRootPart.Position, HumanoidRootPart.Position)
end)
local Waypoints
if Success and Path.Status == Enum.PathStatus.Success then
Waypoints = Path:GetWaypoints()
end
for _, Waypoint in Waypoints do
NPCHumanoid:MoveTo(Waypoint.Position)
NPCHumanoid.MoveToFinished:Wait()
end
else
end
wait()
end