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:
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!