I am trying to make a stun effect that would also pause/stop/cancel a player’s attack. I have looked through articles and I have tried using coroutine.yield or something but I can’t do it from the outside. I also don’t know how to pause or stop a function or something.
Example of what I want: For example, a player uses a stunning move that freezes the other player for a second (I can stop movement obviously) but, the other player is still able to attack which is what I don’t want. Like, you know how in Black Magic 2 where you attack someone and their attack is canceled and stopped in mid time? That is what I want to achieve. All players use keybinds through local scripts, which fires to a remote event to server side. How would I pause the other player’s script or cancel it so their attack just stops and cancels? Please I need help and I am confused. This is the server side scripts and I am trying to cancel it in mid-time
Also, this is on server side, so disabling the script will disable all player’s attacks.
Scripts:
event.OnServerEvent:Connect(function(player)
-- attack stuff
local debounce = false
attack.Touched:Connect(function(hit)
local enemyhumanoid = hit.Parent:FindFirstChild("Humanoid")
if debounce == false and enemyhumanoid and enemyhumanoid.Health > 0 then
debounce = true
enemyhumanoid:TakeDamage(10)
enemyhumanoid.WalkSpeed = 0 -- i have other ways to stop the player from moving this is just an example
enemyhumanoid.JumpPower = 0-- i have other ways to stop the player from moving this is just an example
-- enemy attack stop?
end
end)
end)
some ways I thought of was putting a variable to see if the player was stunned or not, then it would skip over the attack. But, the problem is I would need like 100 if statements in this function.
I need help, please help, and you can alter/change/suggest what to change to the script or an efficient way but I want it to be able to stop a player’s attack in mid time.
yeah but how do you stop them from attacking if they were already attacking? I would have to put if statements on each attack part, so what you said is the problem i described, too many if statements and it would be over EVERY single line. If the player was already attacking, this would not do anything.
You can use the function above to get an animation track playing on a character or store the value returned by LoadAnimation.
You can then use the function above to stop the animation track. Set the first parameter to 0 to make it stop instantly.
To control the stun, I’d recommend adding an Instance to the player, character, or humanoid (you can also use a BooleanValue as suggested above or a BindableEvent). You can then connect the Instance.ChildAdded event to a function that checks for something named a specific name (ex. “StunnedEffect”). If that happens you can signal weapon code to stop and end connections (touched events, etc.).