Cannot modify a value type return value of `UnityEngine.Transform.localPosition'. Consider storing the value in a temporary variable. HELP

I was following along a tutorial on Youtube but it was written in JS but i translated it to C# but i get that error. Here is my code:

    headBobStepCounter += Vector3.Distance(parentLastPos, transform.parent.position) * headBobSpeed;
    transform.localPosition.x = Mathf.Sin(headBobStepCounter) * headBobAmountX;
    transform.localPosition.y = (Mathf.Cos(headBobStepCounter * 2) * headBobAmountY) + (transform.parent.localScale.y * eyeHeightRatio) - (transform.parent.localScale.y / 2);

The error is indicating you should put the values into a Vector3 first, and then assign the Vector3 to the position:

headBobStepCounter += Vector3.Distance(parentLastPos, transform.parent.position) * headBobSpeed;
Vector3 v3T = transform.localPosition;
v3T.x = Mathf.Sin(headBobStepCounter) * headBobAmountX;
v3T.y = (Mathf.Cos(headBobStepCounter * 2) * headBobAmountY) + (transform.parent.localScale.y * eyeHeightRatio) - (transform.parent.localScale.y / 2);
transform.localPosition = v3T;