Event doesn't reset length's time

Hi, I’m doing a stun event.

If fired on target, it would slow the target down, if fired again, the length should like reset, but it doesn’t do it. any suggestions?
Code:

script.Parent.Stun.Event:Connect(function(target,length)
	target.StatsFolder.HitStun.Value = true

	coroutine.wrap(function()
		for xd = 1,4 do
			target.Humanoid.WalkSpeed = 0.25
			target.Humanoid.JumpPower = 0
			wait(0.05)
		end
	end)()

	delay(length,function() -- completing after waitTime
		if target.StatsFolder.HitStun.Value == true then -- check if current stun is under this thread
			print("still had id reset")
			target.StatsFolder.HitStun.Value = false
			target.Humanoid.WalkSpeed = game.StarterPlayer.CharacterWalkSpeed
			target.Humanoid.JumpPower = game.StarterPlayer.CharacterJumpPower
		else
			print("id not found") -- current stun is not managed by current thread skip
		end
	end)
end)
1 Like

Did you forget to set the HitStun.Value back to true after checking it?

1 Like

What do you mean by exactly? Kinda confused about it unless you’re talking about else section.

Is there any errors in output?

None at all, but when I’m comboing the target, it doesn’t like set the timer.
VV Gif below VV
https://cdn.discordapp.com/attachments/663926114825273344/839600888296898610/sW4e55jlON.gif

Basically, each hit will fire stun with target and length. length on this is 1.1 seconds.

Could you show the code that you are using at this moment?

There you go, not gonna show the entire code obviously.

game.ServerScriptService.Stun:Fire(Character,0.75)

1 Like

One question:

a

1 Like

coroutine is there just to keep keep target’s walkspeed same till target has hitstun = false. I’m not sure what are you trying to do so far.

This part of the code executes during the execution of the next part of the code. But wait, the next part has delay so this part executes 0.75 seconds before the next part.

coroutine doesn’t provoke with delay. I’m not sure what are you on about because its with delay or so. : /

What timer exactly…? You seem to be firing the BindableEvent 3 times in this Instance as shown in the GIF