How to avoid yielding for my cooldown functions

So, basically, I have a script that, when you use an ability, it runs a function. After the function is called, I start the cooldown. The thing is, I want freedom to do what I want in these functions, and I’m worried that, by yielding to anything I do in the functions and THEN waiting the cooldown time, the cooldown is effectively longer than I want it to be. How do I fix that? Is the an alternative to wait() that fixes it? Will coroutine work fine? What do I do?

why do you not run your function in it’s own thread using coroutines or the task library?
Instead of

yourFunction()

you do

task.spawn(yourFunction)

Is there a reason you cannot start the cooldown prior to executing the function? If your question is simply educational, you can use coroutines to enable pseudo-simultaneous code execution:

task.spawn(ability, ...)

-- Cooldown...

For more on why this works, read this related explanation.
For more on the solution, read this article. [API reference]

The wait would yield the script so the function wouldn’t start. I guess with task though, I can start them both off at the same time, so it doesn’t really matter.

Could you please share the code? Even a little from the code? Either way, if you want to yield anything, you can simply do this:

--doing some stuff
task.spawn(function()
    task.wait(4)
    --disable jumping
end)
print("You have 4 seconds left until you can't jump anymore!")