Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you make a wait() only effect a part of a script?

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.

3 comments

0

or maybe making the recharge a seperate script

0

If you post the script, we can help out.

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.