Cannot resume dead coroutine [SOLVED]

“cannot resume dead coroutine” is the error I got in this code

local RS = game:GetService("ReplicatedStorage")
local CameraShaker = require(RS.Modules:WaitForChild("CameraShaker"))
local debounce = false
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://13470967554"
local track1 = game:GetService("Players").LocalPlayer.Character:WaitForChild("Humanoid"):LoadAnimation(Anim)

--Settings--
local Cooldown = 8
local Cooldown2 = 8  --just for the countdown (has to be the same as the first Cooldown)
local ToolBarHideTime = 3
--Settings--

local countdown = coroutine.wrap(function()
	for i=Cooldown2, 0, -1 do
		script.Parent.Name = "Cooldown: ".. i
		task.wait(1)

		if i == 0 then
			script.Parent.Name = "Barrage"
			Cooldown2 = Cooldown
			debounce = false
		end
	end
end)

script.Parent.Equipped:Connect(function()
	if debounce == false then
		debounce = true
		RS.Events.Barrage:FireServer()		
		track1:Play()


		countdown() -- here is the error


		task.wait(Cooldown)
		--debounce = false
	end	
end)

RS.Events.Barrage.OnClientEvent:Connect(function()
	
	game:GetService("Lighting").BlurEffect.Size = 5
	
	game:GetService("TweenService"):Create(game:GetService("Lighting").BlurEffect, TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.InOut, 0, false, 0), {Size = 0}):Play()
	local Shakes = script.ShakeScript:Clone()
	Shakes.Parent = game:GetService("Players").LocalPlayer.Character
	Shakes.Disabled = false
	game.Debris:AddItem(Shakes,3)	
end)

script.Parent.Equipped:Connect(function()
	if debounce == false then
		game:GetService('StarterGui'):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
		task.wait(ToolBarHideTime)
		game:GetService('StarterGui'):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
		track1:Stop()
	end
end)

but I don’t really know what that means and how to fix it.
can someone help me?

The wrap function in your case is possible to run only 1 time
Docs: coroutine | Documentation - Roblox Creator Hub
You can use something like this:

local function countdown()
	for i=Cooldown2, 0, -1 do
		script.Parent.Name = "Cooldown: ".. i
		task.wait(1)

		if i == 0 then
			script.Parent.Name = "Barrage"
			Cooldown2 = Cooldown
			debounce = false
		end
	end
end

task.spawn(countdown)

if you read the post title you would have seen its already solved (still thanks)

You should post the solution you found, and then mark it as the solution. Maybe somebody else has the same problem you had?

2 Likes

Write then what is already solved and mark your message as solved so that the thread is closed.

2 Likes

can’t believe this guy didnt post the solution

4 Likes

function countdown()

coroutine.wrap(countdown)()

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.