Cannot resume dead coroutine

Lately, my server console is being spammed every 3-5 minutes with an error saying “cannot resume dead coroutine”
image

I am also unable to replicate it in studio and it seems like there has to be some trigger that players are doing to cause this error. The timing can sometimes be very consistent (every 3 minutes exactly) or sometimes completely random.

There is no stack trace or anything that could indicate what script is causing this error. I tried searching for the following keywords:
task.[x], coroutine.[x], :Wait(), and :Connect

I would then analyze any server scripts that would utilize these methods and see if there’s something that could be resuming a dead coroutine. We don’t use coroutine functions, but do use task.spawn on the server a few times.

At this point, I’ve exhausted my options and debugging this seems to be moot.

Does anyone know what else I could do to figure out what is causing the error?

I’m thinking it could have to do with our sword arena system. There were a few WaitForChild errors that occurred that I was able to fix by adding something like this top the of the script:

if not Tool or not Tool.Parent then return end

arena_system.rbxm (10.8 KB)

I’ve also attached the arena system if anyone wants to attempt to audit it to see if it could be related to the problem. The code is really shoddy but that’s not my concern since I didn’t write it.

Could you also post it on here using ``` because I’m quite afraid of downloading anything :sweat_smile:

I have this problem before but I forgot about it completely but it was about something I repeated.
Post below could also indicate you have a virus.

Can you tell us which side did you get the error from via the Developer Console? Is it from the server or client?

The error really indicates it has something to do with coroutines 100%, there may be a virus in your game?

1 Like

The error is server-sided. I did mention “analyze any server scripts” but I should’ve been more clear about that. I don’t think there’s any viruses in the game.

serverscript “FightingArena”

local PwnAmountUntilBadge = 20

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local FightingArena = workspace["Script Stuff"].FightingArena
local ArenaZone = FightingArena:WaitForChild("ArenaZone")
local Boundaries = FightingArena:WaitForChild("Boundaries")
local Tools = ServerStorage:WaitForChild("Tools")
local LinkedSword = Tools:WaitForChild("LinkedSword")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local PwnedEvent = Remotes:WaitForChild("PwnedEvent")

local function GiveWeapon(Character :Model, Player :Player)
	for _, v in Character:GetChildren() do
		if v:IsA("Tool") then
			v.Parent = Player.Backpack
		end
	end
	
	local CloneLinkedSword = LinkedSword:Clone()
	CloneLinkedSword.OriginalOwner.Value = Player.UserId
	CloneLinkedSword.Parent = Character
end

local function NotFighting(Player :Player)
	local Fighting :BoolValue = Player.FightData.Fighting
	return Fighting
end


local function Begin(Hit :BasePart)
	local Character = Hit.Parent
	local Player = Players:GetPlayerFromCharacter(Character)
	if not Player then return end
	local Debounce :BoolValue = Player.FightData.FightingDebounce
	if Debounce.Value then return end

	Debounce.Value = true
	local Fighting :BoolValue = NotFighting(Player)
	if not Fighting.Value then
		GiveWeapon(Character, Player)
		Fighting.Value = true
	end
	Debounce.Value = false
end

local function Stop(Player :Player)
	local Fighting :BoolValue = Player.FightData.Fighting
	if not Fighting.Value then return end
	local Character = Player.Character
	local Sword = Player.Backpack:FindFirstChild("LinkedSword")
		or Character:FindFirstChild("LinkedSword")
	if Sword then
		Sword:Destroy()
	end
	Fighting.Value = false
end

ArenaZone.Touched:Connect(Begin)
ArenaZone.Transparency = 1

for _, Boundary :BasePart in Boundaries:GetChildren() do
	Boundary.Touched:Connect(function(Hit)
		local Character = Hit.Parent
		local Player = Players:GetPlayerFromCharacter(Character)
		if not Player then return end
		Stop(Player)
	end)
	Boundary.Transparency = 1
end

serverscript “FightingPlayerAdded”

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

local PlayerData = ServerStorage.FightData


local function AntiTeleport(Player :Player, Tool :Tool)
	if Tool.CanBeDropped then
		Tool.CanBeDropped = false
		return
	end

	local OgNumberValue :NumberValue = Tool:FindFirstChild("OriginalOwner")

	if not OgNumberValue then 
		local numv = Instance.new("NumberValue")
		numv.Value = Player.UserId
		numv.Parent = Tool
		return 
	end

	if OgNumberValue.Value ~= Player.UserId then
		--local OgOwner = Players:GetPlayerByUserId(OgNumberValue.Value)
		Tool:Destroy()
	end
end


Players.PlayerAdded:Connect(function(Player)
	local DataClone = PlayerData:Clone()
	DataClone.Parent = Player
	
	Player.CharacterAdded:Connect(function(Character)
		DataClone:WaitForChild("Fighting").Value = false
		Character.ChildAdded:Connect(function(Child)
			if not Child:IsA("Tool") then return end
			AntiTeleport(Player, Child)
		end)
	end)
end)
1 Like

Scripts look fine to me. I am 99.99% sure it has something to do with coroutines… can you show me any other scripts?

I don’t know what else I could show you without just dumping the entire server back-end. The snippet Happya posted also does not include the LinkedSword script.

These are all the usage of task.spawn:

Most of it is simple task.spawn calls that don’t need to be cancelled because they just do something like :GetChildren(), set properties, and end quickly. We never use task.cancel or any coroutine functions. I’ve crossed out anything that is client-side, not in-use, is a library, etc.

That leaves 2 possible scripts which both look fine to me.

You could narrow down on time specify script or long processing script if it happen every 3-5 minutes. Usually this might happen if a script takes too long to process(By my memory)
Or an issue with reusing variable.

Edit: For an error and because of function limitation the lack of debugging information is really on Roblox. (Maybe just me but parallel is a struggle)

It’s not every 3-5 minutes which is the issue.

It just seems completely random. A person also does not need to purchase anything for the error to occur and sometimes it can take 10+ minutes after a server starts up for the error to start showing.

I’ve done some quick google searches related to that erorr message, it seems like task functions can be a culprit. Can you show us the last 2 possible scripts?

I think I fixed it. We use the Promise lbrary to wait for a bunch of MarketplaceService calls to finish, and it looks like someone didn’t use :catch on any of them.

After doing that I haven’t seen the error for a good 30 minutes.

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