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.
✓ ANSWER ACCEPTED
How do you make a wait() only effect a part of a script?
2 answers
✓ Accepted answer
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
1 comment
0
Thanks aquathorn321 that was exactly what I was looking for
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Try using debounce: http://wiki.roblox.com/index.php?title=Debounce
or maybe making the recharge a seperate script
If you post the script, we can help out.