01 | canFire = true |
02 |
03 | function DoRecoilY() |
04 | -- Code for recoil would be placed in here with waits. |
05 | end |
06 |
07 | function Shoot() |
08 | --Code for shooting a gun would be placed in here. |
09 | end |
10 |
11 | mouse.Button 1 Down:connect( function () |
12 | if canFire = = true then |
13 | canFire = false |
14 | Shoot() |
15 | wait(FireRate) |
16 | canFire = true |
17 | end |
18 | end ) |
Since DoRecoilY has waits in it it would delay how fast you can shoot. I've heard of something called coroutines but I have no idea how to implement them into this. I've looked at the wiki but I'm a little confused.
There are multiple ways to run a coroutine. I'll lay them out for you:
coroutine.wrap
~ call it using a function, and it will create a new, callable coroutine with the body of that function.1 | coroutine.wrap(DoRecoilY)() |
coroutine.create
and coroutine.resume
~ call create to create a thread, call resume to run it.1 | local DoRecoil = coroutine.create(DoRecoilY) |
2 | coroutine.resume(DoRecoil) |
spawn
~ runs a function in a separate thread.1 | spawn(DoRecoilY) |