Made a stun module that I can use over multiple scripts and I thought I could share it with anyone else who might find it useful too. Useful for combat games.
It is very easy to use. All you need to do is pass a humanoid object and the time you want the stun to last for (secs).
It saves the current WalkSpeed and JumpPower of the humanoid before setting them to 0.
If you try to stun a humanoid that is already being stunned, it will compare the remaining time of the previous stun with the new one. If the new stun duration is longer, the duration of the previous stun will be updated to the new one.
When a humanoid is successfully stunned, it will add an attribute named “Stunned” to the humanoid’s parent (generally the character).
If there are problems/ways to optimise, advice is much appreciated! Thanks.
Example
local StunHandler = require(path.to.module)
character:GetAttributeChangedSignal("Stunned"):Connect(function()
print(character:GetAttribute("Stunned"))
end)
StunHandler.Stun(humanoid, 5) -->> Stuns the humanoid for 5 seconds
There are games that have different JumpPower set, not 50.
Other than that, it looks fine, maybe you could improve it by making sure the WalkSpeed/JumpPower don’t get changed while you are stunned with a Humanoid Changed connection (make sure to disconnect when stun duration is over)
does this stun work for things like combo stuns. For example, when you hit someone with a sword combo, they can’t move or do anything until the combo is over or is interrupted.
sometimes players get permanently stunned (i was testing with 3 of my friends and we kept fighting then after a while the moves started to permanently stun whoever was hit instead of stunning for the duration i put.)
edit: nvm it was because the server script was inside of the tool so it would be deleted before the stun would be removed from the other player