Yeah, that code in the Script Console works fine for me too. I can run my script with no errors by pasting it into the Console in the Designer, but as soon as it’s in the Client Events area, I get the issue.

There’s a bit to it but I’ve attached a stripped-down version of the script with the relevant sections. You should be able to put an arbitrary array of angles in degrees into the function provided here.

```
import math
def averageAngles(angle_array):
"""
Takes array of angles in degrees and finds the average. Each angle is used to create a unit vector with x and y
components using cosine and sine definitions. Components are then summed and divided by the number of angles to
produce x' and y'. Average coordinates are then used to calculate the average angle using the atan2() method, a
version of arctan / inverse tangent which preserves angle sign across all four quadrants.
Inputs:
angle_array (array): One-dimensional array containing angles (in degrees) to be averaged
Returns:
angle_prime (float): Average angle calculated from array. Angles are given between 0 and 360 degrees, with a
value of -1 indicating a "None" angle in the situation where the net vector is null
"""
angle_count = 0
x_prime = 0
y_prime = 0
for angle in angle_array:
if angle != "None" or angle != -1:
# Convert to radians, find x and y components for an angle defined from North heading
theta = math.radians(angle)
x = math.cos(theta)
y = math.sin(theta)
# Add new x and y to x' and y' accumulators
x_prime += x
y_prime += y
# Increase angle count
angle_count += 1
# Check if angle_array is empty or angle is null condition
if angle_count != 0 and (x_prime != 0 and y_prime != 0):
# Divide accumulators by number of angles to find average
x_prime = x_prime / angle_count
y_prime = y_prime / angle_count
# Calculate inverse angle from average x and y positions
theta_prime = math.atan2(y_prime, x_prime)
angle_prime = math.degrees(theta_prime)
# Bound angle to positive conditions between 0 and 360
if angle_prime < 0:
angle_prime += 360
# Return calculated angle
return angle_prime
else:
# Null condition
return -1
#
# date = system.tag.read("[Client]date_tagpath").value
# Populate day[] with shift timestamps from date
#
day_angles = []
for shift in day: # Day is array of relevant timestamps
#
# Code to fetch dataset from database here. Create shift_data array of angles in degrees eg. [45, 90, 270, 340]
#
shift_angles = averageAngles(shift_data)
day_angles.append(shift_angles)
#
# Create new dataset from day_angles
# system.tag.write("[Client]dataset_tagpath", dataset)
#
```