Hello I tried to make an automatic riffle in my game with coroutine
I've done that
local function autoFire()
local replicateRate = 6
local counter = 0
autoFireCoroutine = coroutine.create(function()
while equipped and weaponData.ammo.Value > 0 and weaponData.Configs.Info:GetAttribute("currentShootingMode") == "automatic" do
counter += 1
local shouldReplicate = counter % replicateRate == 0
fire(shouldReplicate)
task.wait(defaultStats:GetAttribute("baseAutomaticFireDelay"))
end
end)
coroutine.resume(autoFireCoroutine)
end
but i'm not sure if this is the best, and most optimized way
Thanks!