How to do i return an object to it initial local position after moving

I am trying to make procedural animation and i want both leg iks return to there initial position relative to the character
actual code:

using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine;

public class PAS2 : MonoBehaviour
{
    [SerializeField] private Transform LIkTarget;
    [SerializeField] private Transform RIkTarget;
    [SerializeField] private Transform Hips;
    [SerializeField] private Transform ikPivot;

    [SerializeField] private Vector3 RrayPos;
    [SerializeField] private Vector3 LrayPos;

    private Vector3 LastHipPos;
    private Vector3 LastHipPosDist;
    private Vector3 Velocity;

    private Vector3 indicatorR;
    private Vector3 indicatorL;

    private bool Rfoot;
    private bool Lfoot;

    [SerializeField] private float MaxDistance;
    [SerializeField] private float LerpSpeed;
    [SerializeField] private float StrideLength;
    private float Distance;
    private float TrueMaxDist;
    /*float Dist;
    float NearestDist = .625f;*/

    GameObject Lray;
    GameObject Rray;
    public GameObject NearstOBJS;
    private GameObject[] ALLObjects;
    RaycastHit hit;

    // Start is called before the first frame update
    void Start()
    {
        Lray = GameObject.CreatePrimitive(PrimitiveType.Cube);
        Lray.transform.localScale = Vector3.one * 0f;
        Lray.transform.parent = ikPivot;
        Lray.transform.localPosition = LrayPos; 
        //////////////////////////////////////////////////////////////
        Rray = GameObject.CreatePrimitive(PrimitiveType.Cube);
        Rray.transform.localScale = Vector3.one * 0f;
        Rray.transform.parent = ikPivot;
        Rray.transform.localPosition = RrayPos;

        LastHipPos = Hips.position;

        TrueMaxDist = MaxDistance * 2;

        Lfoot = false;
        Rfoot = true;

        RrayPos.z = StrideLength;
        LrayPos.z = StrideLength;
    }

    // Update is called once per frame
    void Update()
    {
        Velocity = Hips.position - LastHipPosDist;
        Velocity /= Time.deltaTime;

        ALLObjects = GameObject.FindGameObjectsWithTag("floor");

        Distance = Vector3.Distance(Hips.position, LastHipPos);

        if (Velocity.magnitude > .01)
        {
            ikPivot.rotation = Quaternion.LookRotation(Velocity, Vector3.up);
        }

        if (Velocity.z < 0)
        {
            if (Distance > MaxDistance & Lfoot & !Rfoot)
            {
                RIkTarget.position = indicatorL;
                LastHipPos = Hips.position;
                Lfoot = false;
                Rfoot = true;

                MaxDistance = TrueMaxDist;
            }
            else if (Distance > MaxDistance & Rfoot & !Lfoot)
            {
                LIkTarget.position = indicatorR;
                LastHipPos = Hips.position;
                Lfoot = true;
                Rfoot = false;
            }
        }
        else if (Velocity.x < 0)
        {
            if (Distance > MaxDistance & Lfoot & !Rfoot)
            {
                RIkTarget.position = indicatorL;
                LastHipPos = Hips.position;
                Lfoot = false;
                Rfoot = true;

                MaxDistance = TrueMaxDist;
            }
            else if (Distance > MaxDistance & Rfoot & !Lfoot)
            {
                LIkTarget.position = indicatorR;
                LastHipPos = Hips.position;
                Lfoot = true;
                Rfoot = false;
            }
        }
        else
        {
            if (Distance > MaxDistance & Rfoot & !Lfoot)
            {
                RIkTarget.position = indicatorR;
                LastHipPos = Hips.position;
                Lfoot = true;
                Rfoot = false;


                MaxDistance = TrueMaxDist;
            }
            else if (Distance > MaxDistance & Lfoot & !Rfoot)
            {
                LIkTarget.position = indicatorL;
                LastHipPos = Hips.position;
                Lfoot = false;
                Rfoot = true;
            }
        }

        float Range = 0.5f;

        if (Physics.Raycast(Lray.transform.position, -Vector3.up, out hit, Range))
        {
            indicatorL = hit.point;
        }
        if (Physics.Raycast(Rray.transform.position, -Vector3.up, out hit, Range))
        {
            indicatorR = hit.point;
        }

        /*for (int i = 0; i < ALLObjects.Length; i++) 
        {
            Dist = Vector3.Distance(LIkTarget.position, ALLObjects[i].transform.position);

            if(Dist < NearestDist) 
            {
                NearstOBJS = ALLObjects[i];
                NearestDist = Dist;
            }
        }*/

        LastHipPosDist = Hips.position;
    }

   /* IEnumerator WalkL()
    {

        float timePassed = 0;
        while (timePassed < LerpSpeed * 10)
        {
            timePassed += Time.deltaTime;
            LIkTarget.position = indicatorL;
            yield return null;
        }
       
    }
    IEnumerator WalkR()
    {

        float timePassed = 0;
        while (timePassed < LerpSpeed * 10)
        {
            timePassed += Time.deltaTime;
            RIkTarget.position = indicatorR;
            yield return null;
        }

    }
    IEnumerator WalkLI()
    {

        float timePassed = 0;
        while (timePassed < LerpSpeed * 10)
        {
            timePassed += Time.deltaTime;
            LIkTarget.position = indicatorR;
            yield return null;
        }

    }
    IEnumerator WalkRI()
    {

        float timePassed = 0;
        while (timePassed < LerpSpeed * 10)
        {
            timePassed += Time.deltaTime;
            RIkTarget.position = indicatorL;
            yield return null;
        }

    }*/
}

some stuff are not needed but were experimental

Your velocity variable will not compile there. Statements need to be within method bodies. Your code will be easier for us to review if you follow these c# naming conventions (Identifier names - rules and conventions - C# | Microsoft Learn).

I assume the iktarget objects are a transform for each foot. Initial pos variables are stuck where the feet began in the 1st frame. Instead, you’ll want to define initialPos for each foot relative to the current position of the most stable part of the rig (usually the spine). You can do that w/ Vector3 variables, but you’ll have to update them every frame manually to keep them correct. Instead, I recommend making your initial pos variables transforms also, so that you can set parent to be the spine for each. Then they will always be in the correct relative position automatically.

Linitialpos and Rinitialpos are worldspace coordinates, not local to your rig. See Unity docs for ‘Transform.position’ vs ‘Transform.localPosition’.

Once you’ve sorted out scripting local vs. global, you’ll probably want to define a threshold as velocity approaches zero. With physics, it can take quite a while for velocity to actually hit 0.

Also, once your idle condition is satisfied, I recommend interpolating toward the target rather than snapping to it. See Vector3.Lerp(), Vector3.Slerp(), Vector3.SmoothDamp(), Quaternion.Lerp(), Quaternion.Slerp(), etc. in Unity docs. There are also lots of tweening libraries that may be useful here. Search “tweening” on the Asset Store.