- What do you want to achieve?
I want to clear the error being produced “cannot resume dead coroutine”
- What is the issue?
I’m not able to find where or what is causing this error to produce. This seems to occur right after when the reload time finishes.
- What solutions have you tried so far?
What I have attempted to do is to create a boolean for the thread running and cancel it when I unequipped my weapon. I have also tried to cancel tween in my function below, but it doesn’t seem to remove that message. I believe some thread is still running after I have canceled the thread.
Also if you like, let me know what I can do to improve upon what I have written in my code
-- module script
function gunMechanic.reload(localPlayer, weapon)
if Bullet_is_not_same and Is_not_reloading then
local gunMechanic = require(ReplicationStorage.gunMechanic) -- visual cooldown GUI using tween, no wait/delay
weapon.reload = true
local cooldownTween = gunMechanic.cooldown(localPlayer, weapon, weapon.configuration.stat.RELOAD_TIME.Value)
local threadRunning = true
local delayThread = coroutine.create(function()
print("reloading...")
wait(weapon.reload_time)
print("reloaded")
threadRunning = false
BULLET_IN_CLIP.Value = AMMO_CAPACITY.Value
weapon.reload = false
end)
task.spawn(delayThread)
while weapon.reload.Value == true and weapon.equipped.Value == true do
task.wait() -- ends thread when unequipped or finish reloading
end
print("reload finish or interrupted")
if threadRunning == true then
cooldownTween:Cancel()
task.cancel(delayThread)
end
end
end