You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I’m trying to cancel a task so the effect doesnt get it’s value reset -
What is the issue? Include screenshots / videos if possible!
The task isn’t getting cancelled so the value keeps getting reset
local module = {}
local effects_in_place = {}
function module:Add_New_Effect(who, what: string, duration: number, amount: number, time_to_wait_between_loops: number, stackable: boolean)
spawn(function()
--if game:GetService("Players"):GetPlayerFromCharacter(who) then
for i,v in ipairs(effects_in_place) do
if v.name == what then
if v.stackable == false and v.owner == who then -- check if the effect is stackable
if v.lightingeffect == true and game:GetService("Players"):GetPlayerFromCharacter(who) then
game.ReplicatedStorage.lighting:FireClient(game:GetService("Players"):GetPlayerFromCharacter(who), "ColorCorrection", 0.2, Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, true, 0, 0.1, true, 0.1, Color3.new(1, 1, 1))
end
if v.name == "speed" then
who.Humanoid.WalkSpeed -= v.amountt
end
if v.name == "protection" then
who.enemydmgmultiplier.Value += 0.15
end
if v.name == "strength" then
who.dmgmultiplier.Value -= 0.15
end
if v.name == "berserk" then
who.specialeffects.berserk.Value = false
end
task.cancel(v[what]) -- not getting cancelled
table.remove(effects_in_place, table.find(effects_in_place, v))
end
end
end
if what == "expose" then -- issue
local newtable = {
name = what,
stackable = stackable,
owner = who,
amountt = amount,
lightingeffect = false,
["expose"] = task.spawn(function()
who.enemydmgmultiplier.Value += 0.05
task.wait(duration)
print("task didnt get cancelled") -- this is still printing
who.enemydmgmultiplier.Value = 1
end)
}
table.insert(effects_in_place, newtable)
task.wait(duration)
task.cancel(newtable.expose)
table.remove(effects_in_place, table.find(effects_in_place, newtable))
end
This is a piece of code from the module