Help with Stun Handler

I want to Fix this Stun Handler up, but for some reason, the Value in the StunTable[Enemy] doesn’t change!

I’ve tried everything I could but I just couldn’t get it to update its value in the repeat loop for some reason.
For exmaple:

I run the function with a Duration of 2, and after I re-run it 1 second later and a duration of 2 again, it still keeps repeating the function I ran the first time.

function ModifierHandler:Stun(Enemy, Duration)
	coroutine.wrap(function()
		local Duration = Duration or 0;

		if (not StunTable[Enemy]) then
			StunTable[Enemy] = Duration;

			SpeedHandler:ChangeSpeed(Enemy, 4, 0);

			StateHandler:UpdateState(Enemy, "Stunned", true);

			repeat
				StunTable[Enemy] -= task.wait();
			until StunTable[Enemy] <= 0;

			StateHandler:UpdateState(Enemy, "Stunned", false);

			SpeedHandler:ChangeSpeed(Enemy, "default", "default");

			StunTable[Enemy] = nil;

		elseif (Duration >= StunTable[Enemy]) then
			StunTable[Enemy] = Duration;
		end
	end)();
end
2 Likes