canFire = true function DoRecoilY() -- Code for recoil would be placed in here with waits. end function Shoot() --Code for shooting a gun would be placed in here. end mouse.Button1Down:connect(function() if canFire == true then canFire = false Shoot() wait(FireRate) canFire = true end 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.coroutine.wrap(DoRecoilY)()
coroutine.create
and coroutine.resume
~ call create to create a thread, call resume to run it.local DoRecoil = coroutine.create(DoRecoilY) coroutine.resume(DoRecoil)
spawn
~ runs a function in a separate thread.spawn(DoRecoilY)