im new with coroutine and i thought i would be fit for what im doing. i have a function that lowers a gauge progresively over time, but when the player dies the gauge should lowering and remain. For this i made a function to lower it, and call it when i need. when the player dies, the .Died Event is fired and the coroutine should close. At least that was my idea but the coroutine doesn't close i think the code i made is clearly not what should be done
local Deplete = nil
LocalPlayer.CharacterAdded:Connect(function()
local Deplete = nil --Reset the variable on death
end)
--The function to lower the gauge
function DepleteGauge(Rate)
local Gauge = LocalPlayer.UltGauge
Gauge.Value = 99
for i = 0,98 do
task.wait(0.5)
Gauge.Value = Gauge.Value - Rate
end
end
function ArchAngel()
--code [...]
Deplete = coroutine.create(DepleteGauge(1))
end
--Test if the gauge is depleting, if yes stop it
LocalPlayer.Character.Humanoid.Died:Connect(function()
if Deplete ~= nil then
coroutine.close(Deplete)
end
end)```
** You are now Level 6! **