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

How to make a cooldown in a script without using wait()?

I have a custom gun script in my game with animations. I use :GetPropertyChangedSignal() for the animations to make sure they are done playing before the player can aim, but the problem with this is that if you try to aim before it's finished playing, the gun won't work anymore. If you were to use wait() here, it would yield the entire script and also break it. How can I make a cooldown for this that won't actually yield the entire script?

1 comment

0

Use a debounce?

2 answers

✓ Accepted answer

you can use delay(t, func) to run a function in a separate thread after a certain amount of time

the actual delay part (aka the part where it waits before running the function) won't yield the thread it was called in

edit because you asked for an example:

delay(5, function()
	print("awesome!")
end)
print("cool!") -- cool! prints first, even though it's after the delay, because the delay runs in a separate thread

3 comments

0

Can you give an example?

0

example given

0

Worked. Thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.