Coroutine Assistance `attempt to call a thread value `

Trying to make a simple co-routine here which allows for a loop to be made.

-- // Coroutine to deal with filter amount
function Depreciate(EquipTime)
	local LowFilterSoundCoolDown = false
	local SoundEffects = ConfigInstance:GetAttribute(`SoundEffects`)
	local FilterSway = ConfigInstance:GetAttribute(`FilterSway`) + EquipTime -- // gets the cooldown + the equiptime
	RunService.Heartbeat:Connect(function()
		if ConfigInstance:GetAttribute(`Equipped`) == true then
			if os.time() - FilterSway >= 0 then -- // if the current time is larger then
				FilterSway = ConfigInstance:GetAttribute(`FilterSway`) + os.time()
				local CurrentFilterAmt = ConfigInstance:GetAttribute(`FilterAmt`)
				if CurrentFilterAmt <= 25 and SoundEffects then
					if not LowFilterSoundCoolDown then
						LowFilterSoundCoolDown = true
						Hat:FindFirstChild(`Handle`):FindFirstChild(`LowFilter`):Play()
						task.wait(ConfigInstance:GetAttribute(`FilterSway`)*2) -- // pray that filtersway isnt a big number
						LowFilterSoundCoolDown = false
					end
				end
				if CurrentFilterAmt == 0 or ConfigInstance:GetAttribute(`FilterDecrease`) - CurrentFilterAmt < 0 then
					if FilterMesh then FilterMesh.Transparency = 1 end
					task.spawn(DamageCo)
				else
					ConfigInstance:SetAttribute(`FilterAmt`,CurrentFilterAmt-ConfigInstance:GetAttribute(`FilterDecrease`))
					if FilterMesh then FilterMesh.Transparency = 0 end
					task.cancel(DamageCo)
				end
			end 
		end
	end)
end
local DepreciateCo = coroutine.create(Depreciate)

-- // Initalise
function SetUpConfig()
	Hat.Handle:FindFirstChild(`Poweron`):Play()
	for Name,Data in ConfigData do
		for ElementName,ElementData in Data do
			--print(ElementName) ; print(ElementData)
			ConfigInstance:SetAttribute(tostring(ElementName),ElementData)
		end
	end
	if ConfigInstance:GetAttribute(`IsDevMode`) == true then return end
	task.spawn(DepreciateCo(os.time()))
end
SetUpConfig()

The issue returned is:
image
Line 98:

task.spawn(DepreciateCo(os.time()))

Why is this apparent? Is this not how you do coroutines with task.spawn?
Any insight would be appreciated!

Also, a note, I have tried doing coroutine.resume(DepreciateCo(os.time())) instead, it still returns the same error.

The first problem is that you cannot use task.spawn on a coroutine. Instead, use coroutine.resume on the coroutine. The second problem is that you are calling DepreciateCo as a function. Instead of calling it, pass it as the first parameter to coroutine.close and the arguments the function would take as the rest of the parameters. Example: coroutine.resume(DepreciateCo,os.time())

1 Like

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