:SetNetworkOwner() isn't working on my NPC

I tried SetNetworkOwner() on my NPC whenever it moves because when a player is near him the NPC then will start lagging and its movement will become choppy, but the problem is that SetNetworkOwner is not making any difference for some reason. even though I tried checking if it runs the code or not and it was running perfectly fine.

The main code of the first movement of my NPC:

local function MoveNPC(chosenWaypoint)
	
	local success, errorMessage = pcall(function()
		path:ComputeAsync(humanoidRootPart.Position,chosenWaypoint.Value)
	end)
	
	if success and path.Status == Enum.PathStatus.Success then
		
		blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)

			if blockedWaypointIndex >= nextWaypointIndex then

				blockedConnection:Disconnect()

				MoveNPC(chosenWaypoint)
			end
		end)
		
		waypoints = path:GetWaypoints()
		
        -- the main part of the code
		for _,part in pairs(npc:GetChildren()) do
			if part:IsA("BasePart") and part:CanSetNetworkOwnership() then
				part:SetNetworkOwner(nil)
			end
		end
        --==================================================
		
		nextWaypointIndex = 2
		humanoid:MoveTo(waypoints[nextWaypointIndex].Position)	
		
		require(game.ServerScriptService.StoreScripts.StoreModules.RestockNpcModule).Move(reachedConnection,humanoid,nextWaypointIndex,waypoints,walkAnim,blockedConnection
		,GrabBoxOrientations,chosenWaypoint,humanoidRootPart,TweenIO,idle1,idle2,path,grabbingBoxAnim,boxHoldAnim,RestockWaypoints,npc,RestockOrientations
		,boxReleasing,organizingShelves)

	end	
end

You are setting the network owner to nil which is the server. Try using BasePart | Roblox Creator Documentation instead, or manually set the network owner to the player.

That’s what makes the NPC choppy, isn’t it? The constant switch between network ownership of a client and the server.

Not really sure. That’s why I mentioned to either do that or manually set the network owner to the player.

In a server script just try setting the primary part’s ownership to the server(nil). If that doesn’t work then the problem probably isn’t related to network ownership