How to restart a whole function

Alright, How do you restart a whole function when it is called twice.

Example:

   local i = 0
    function Restart()
       print(“function started”)

       repeat wait(1)
          print(“function wait”)
          i = i + 1
       until i = 10
       print(i)
    end

How would I make it so, when the function is called a second time while it is already running, it ends the currently running function, and restarts from the beginning Any help would be appreciated.

You will need to break out of the loop when it’s called a second time.
There is no practical way of “restarting” other than something like this:

local restartRunning = false;
local function restart()
    print("function started");
    repeat wait(1)
       if restartRunning then return end;
    end
end

What is your use case for this? I’m struggling to think of a good reason you’d want to do this, but I think there’s a better solution to whatever your problem is.