Code flickering flashlight

Hi guys! I’m coding my first 3d project and I’m planning on having a flashlight that eventually dies/flickers before it turns off after a period of time and you have to press a button (spacebar) to turn it back on. Is there a way to do this? I don’t have a code for this yet but I attached a light to my player/camera so it stays with it on screen so all I have to do is to code the light/flashlight. Thank you so much! <3