How to enable enqueue_script to work with a logged in user?

Additionally, apart from the “where” of your wp_enqueue_script() function (i.e. theme, plugin, etc.), the “when” is also important, in terms of WP’s Action Reference hooks, and the order in which they’re fired.

There are 2 distinct script-related hooks, wp_enqueue_scripts and admin_enqueue_scripts, which allow for separation of scripts and styles depending on which view the user currently has.

If you’re not hooking your wp_enqueue_script() function into one of these properly, this would be one potential cause of the problem.

Providing the code in question will help us find the answer.

EDIT: if you need/want the script to only be enqueued for logged-in, non-admin users, you can wrap it with a two-part conditional evaluator, similar to this:

if( is_user_logged_in() && !current_user_can( 'administrator' ) ) {
    // enqueue stuff goes here
}

That’s the most basic method of testing the conditions you’ve provided, but it’s important to note, there’s better, more regimented, methods of determining a user’s role type and capabilities, than current_user_can() as this simple function only returns the role type, and not specific capabilities that may have been added/removed to/from a role type via a plugin or customization elsewhere in the theme, and those changes may or may not impact your end goal.