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?
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:
Call the function from the client. However, use a RemoteEvent to give a call to the server. Then,
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).
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.
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.
This isn’t the best way to do that because of you stack a
stun = true
task.wait(1)
stun = false
multiple times there will be a period where stun is false when it is supposed to be true.
I think the better way is to add a number attribute named Stun and make the value workspace:GetServerTimeNow (whatever it is called I forgot) and add that by how long you want to be stunned for. Then every frame check if the current time is greater than Stun, change the walk speed and jump power to normal. If it’s not make walk speed and jump power to zero