I want to make a script that allows the player to create lightning, but I want to a a charge function. The only problem is that I would need a wait for ever single time it charged up, but that wait would interfere with the rest of the script.
To run separate pieces of code at the same time in a script, you can use Coroutines. These allow you to run code on separate threads in the same script, so the code can still send and receive information in the same script while separate pieces of code can run independently.
Example:
print(1) coroutine.resume(coroutine.create(function() wait(1) print(3) end)) print(2) --Output: 1 2 3
If you are wanting to let the lightning charge up before you can use it again, then use an if statement to make sure that the lighting charge value is what you want it to be before you can use it again. This is also called a debounce.