Answered by
5 years ago Edited 5 years ago
Hello MajinBluee!
Since you don't want "wait()" to affect your whole script, you can use coroutines!
So basically, each time you use a coroutine you technically make a script inside a script!
It may sound confusing but a coroutine allows you to make your own cooldown system without any interruptions!
Here is an example.
01 | local UIS = game:GetService( "UserInputService" ) |
03 | local TIMES_PRESSED = 0 |
06 | print (game:GetService( "Players" ).LocalPlayer.Name .. " pressed the E key based on delay " .. TIMES_PRESSED .. " times!" ) |
10 | UIS.InputBegan:Connect( function (Input, PROC) |
11 | if Input.KeyCode = = Enum.KeyCode.E and not PROC then |
12 | if DELAY = = false then |
14 | TIMES_PRESSED = TIMES_PRESSED + 1 |
17 | coroutine.resume(coroutine.create( function () |
So, to create a coroutine, you simply have to use the "coroutine.create()" function inside a variable, and in order to use it, you have to use the "coroutine.resume()" function, you simply
have to use the created coroutine as the argument for "coroutine.resume()", and you are all done!
Another example.
1 | local YourCoroutine = coroutine.create( function () |
6 | coroutine.resume(YourCoroutine) |
You can also click HERE to get more info about coroutines!