I have a temporary system for handling how players get stunned when they take damage. I do plan on changing this script later, but I am still curious as to why it is stopping animations too late. As soon as a Stun Value is changed, it will activate the animation instantly, then after the wait() is does everything on time, except stopping the animation. The longer the wait time is, the longer it takes to stop the animation. It's almost like it's a few seconds behind what I tell it to wait.
script: (server script in Backpack)
local Player = script.Parent.Parent.Parent
local Char = workspace:WaitForChild(Player.Name)
local Status = Player:WaitForChild("Status")
local Stuns = Player:WaitForChild("Stuns")
local Animation = Char.Humanoid:LoadAnimation(game:GetService("ReplicatedStorage").Animations.Stuns.ChestStun)
local CrushAnim = Char.Humanoid:LoadAnimation(game:GetService("ReplicatedStorage").Animations.Stuns.Crush)
Status.HitBy1:GetPropertyChangedSignal("Value"):Connect(function()
wait(0.7)
Status.HitBy1.Value = false
end)
Stuns.ShortStun:GetPropertyChangedSignal("Value"):Connect(function()
Animation:Play()
local BP = Instance.new("BodyPosition")
BP.Name = "StunBP"
BP.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BP.Parent = Player.Character.HumanoidRootPart
BP.Position = Player.Character.HumanoidRootPart.Position
wait(1)
Animation:Stop()
Stuns.ShortStun.Value = false
BP:Destroy()
end)
Status.HitBy5:GetPropertyChangedSignal("Value"):Connect(function()
wait(1)
Status.HitBy5.Value = false
end)
Stuns.MedStun:GetPropertyChangedSignal("Value"):Connect(function()
Animation:Play()
local BP = Instance.new("BodyPosition")
BP.Name = "StunBP"
BP.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BP.Parent = Player.Character.HumanoidRootPart
BP.Position = Player.Character.HumanoidRootPart.Position
wait(5)
Animation:Stop()
Stuns.MedStun.Value = false
BP:Destroy()
end)
Status.HitBy10:GetPropertyChangedSignal("Value"):Connect(function()
wait(1)
Status.HitBy10.Value = false
end)
Stuns.LongStun:GetPropertyChangedSignal("Value"):Connect(function()
Animation:Play()
local BP = Instance.new("BodyPosition")
BP.Name = "StunBP"
BP.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BP.Parent = Player.Character.HumanoidRootPart
BP.Position = Player.Character.HumanoidRootPart.Position
wait(10)
Animation:Stop()
Stuns.LongStun.Value = false
BP:Destroy()
end)
Stuns.Crush:GetPropertyChangedSignal("Value"):Connect(function()
CrushAnim:Play()
local BP = Instance.new("BodyPosition")
BP.Name = "StunBP"
BP.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BP.Parent = Player.Character.HumanoidRootPart
BP.Position = Player.Character.HumanoidRootPart.Position
wait(1)
CrushAnim:Stop()
Stuns.Crush.Value = false
BP:Destroy()
end)
Thanks for reading

2 comments
https://developer.roblox.com/api-reference/function/Humanoid/GetPlayingAnimationTracks try using this api
Unfortunately using that causes the animations to never stop. Thanks though