Can't get setFieldValue to work I've got this

    // Creating users through frontend
    Event::on(Users::class, Users::EVENT_BEFORE_ACTIVATE_USER, function(UserEvent $event) {
        $userId = $event-&gt;user-&gt;id;

        // Allow assigning user groups through the frontend (circumvent elevated user sessions)
        $groupId = Craft::$app-&gt;getRequest()-&gt;getBodyParam('userGroup');
        if ($groupId) {
            Craft::$app-&gt;getUsers()-&gt;assignUserToGroups($userId, [$groupId]);
        }

        // This does not work
        Craft::$app-&gt;users-&gt;getUserById($userId)-&gt;setFieldValue('discountPercentage', 15);
    });


Assigning the user group works fine, so I don't get why assigning a field value doesn't. The discountPercentage field is a simple Number fieldtype

I also tried $event-&gt;user-&gt;setFieldValue('discountPercentage', 15); without success.

Also I tried surrounding 15 in quotes, like '15', but that didn't work either.

Edit:

Submitting the "create user form" through the frontend gives no errors. discountPercentage is just left blank.
If you are going to set the fieldValue, you need to save the element:

    $userObject = Craft::$app-&gt;users-&gt;getUserById($userId);
    $userObject-&gt;setFieldValue('discountPercentage', 15); 
    Craft::$app-&gt;elements-&gt;saveElement($userObject);


Should do the trick.