On tick add up Delta Seconds to stamina variable. Tick executes on every frame while delta seconds got estimated time between ticks, if you add you delta seconds you will count time, you can add it to any variable so it grows over time, you speed up and speed down growth by multiplying or dividing the delta seconds. to control when it grow, you just need to put some condition before adding up delta seconds
I want to add in my game stamina, and that stamina to be used whenever I press a specific button and to slowly grow when I release it.
My favorite way is to use the math Min function where one input is the new value with deltatime added onto it, and the other input is the maximum the value is allowed to be. This works great because Min always picks the smaller of the two. So then I just set the value to the output of that Min.