Script not executing for average user

I have a script (DocumentTree, children) which should execute for an average user. This user shold not be able to edit the page with the script.

The page was last edited by a user with script and admin permission. The user has view permission; page is shown but the script does not execute

I get the page to execute the script for the user only if the user is granted admin permission.

xwiki 9.6 , anybody an idea?

Edit: It seems a simple script is executing, but one like this which should list (sub-) pages does not.

Edit2: this is the script:
{{velocity}}
{{documentTree root=“document:$doc.documentReference” /}}
{{/velocity}}

Edit3: A user needs admin permission either globally or in the xwiki tree for that script to work.But thats not intended of course.

Thx Bob

That would mean the script itself directly or indirectly check the current user right.

certainly; but why does it need admin right in the xwiki path ?!

On the page that holds the script you pasted? That’s not enough. The user needs to have view access to the pages that define the document tree macro (XWiki.DocumentTree, XWiki.DocumentTreeMacros and any other pages needed by these two). Otherwise the user doesn’t have access to the document tree macro code. Did you restrict view access to the XWiki page and its children?

Yes, xwiki path access is restricted, because there you find also the user profiles.

But restricting with view access seems not to be enough, the script runs only when the average user has “admin” permission.