I have a stun function in a local script that is fired whenever the local player should be stunned, in this function, I check if the player is currently swinging and if they are I stop the swing animation track, destroy it, then play the stun animation.
I find, sometimes, when a player is stunned, instead of the stun animation playing, the character that has been hit just freezes in their current animation not playing the stun animation (sometimes this is only evident locally and other players cannot even see this frozen animation).
As for what I’ve already tried:
- I’ve added :Destroy() to the animation track in hopes it would make sure the player cannot be stuck in animation but that didn’t seem to work and I’m stumped.
Here’s my code:
local function stunClient(stunType)
if stunType == "Light" then
local lightStunAnim = char.Humanoid:LoadAnimation(stunAnims[1])
if swingAnimTrack and rcHbV4:GetHitbox(char) then
swingAnimTrack:Stop()
swingAnimTrack:Destroy()
rcHbV4:GetHitbox(char):HitStop()
end
lightStunAnim:Play()
changeStatus:InvokeServer({Status="Stunned", Value = true})
char.Humanoid.WalkSpeed = 0
char.Humanoid.JumpHeight = 0
task.wait(lightStunTime)
changeStatus:InvokeServer({Status="Stunned", Value = false})
char.Humanoid.WalkSpeed = 16
char.Humanoid.JumpHeight = 7.2
else
local heavyStunAnim = char.Humanoid:LoadAnimation(stunAnims[2])
if swingAnimTrack and rcHbV4:GetHitbox(char) then
swingAnimTrack:Stop()
swingAnimTrack:Destroy()
rcHbV4:GetHitbox(char):HitStop()
end
heavyStunAnim:Play()
changeStatus:InvokeServer({Status="Stunned", Value = true})
char.Humanoid.WalkSpeed = 0
char.Humanoid.JumpHeight = 0
task.wait(heavyStunTime)
changeStatus:InvokeServer({Status="Stunned", Value = false})
char.Humanoid.WalkSpeed = 16
char.Humanoid.JumpHeight = 7.2
end
end
Help appreciated, thanks.