Whats the best way to go about a stun?

Hello everyone,

I see in a lot of battlegrounds games where if you are attacked, for example with an M1, you are stunned for a brief period of time, and cannot move or attack. I know how to prevent attacking (Attributes), however, I find it difficult to create an optimized way to have a humanoids’ walkspeed be lowered for a certain duration. if fact, setting anything to something specific for a duration on a player that is not the client using the ability is something I find to be difficult.

Did i explain this well?

What is the best way to make an optimized version of this?

I can elaborate if necessary.

Are you trying to instantly set the player speed to be the speed you go at when stunned, or are you trying to do something with TweenService to gradually decrease the speed?

Also, what you can do is that:

  1. Call the function from the client. However, use a RemoteEvent to give a call to the server. Then,
  2. Make checks (if <condition> then <do this> end kind of thing) in the server script to make sure that the other player is actually stunned and that it is not from some exploit.

If you are worried about setting the player walkspeed from the server instead of the client, you can do it from the client and set a state from the server that the player has a slowdown mode on it. Just do RunService.Heartbeat and make sure that the player’s position (whenever moving) corresponds to their slowdown (and if not, they are probably exploiting).

Let me know if this works.

yeah, but after a duration it would reset IF THE TARGET WAS NOT ATTACKED AGAIN UNTIL THE DURATION IS COMPLETED. if i were to do it that way, it would contradict itself unfortunately.

also, no tween. just straight to zero

What you can do is have a boolType (I believe that is what it is called) and set it to be true while the stun is in place. Then do task.wait(num of seconds) and then set it to be false. Just do this from the server scripts.

Then, you can also add another condition in the RunService.Heartbeat and say that if the boolType is false, then the player should be moving at a normal speed.