Hi, I have a sword where when it equips it uses an animation that is looped with the priority of Movement to hold the character’s arm in an upright position.
When I try to disequip it, the animation stays.
I’ve tried stopping the animation tracks then using a higher priority animation to stop that, but it didn’t work. The higher priority animation only moved the characters arms down for a bit, but then it went back to the above image again.
Code used to stop it:
local AnimationTracks = Player.Character.Humanoid:GetPlayingAnimationTracks()
for i, v in pairs(AnimationTracks) do
v:Stop()
end
local AH = Player.AnimationHolder
AH.AnimationId = Animations.ResetAnimation
Player.Character.Humanoid:LoadAnimation(AH):Play()
No, I don’t use while loops for animations since those eventually should break due to the animation limit at about 255. I have it in a local script which is in the sword, but should have been destroyed. It only runs once.
Alright so AH.AnimationId = Animations.ResetAnimation should that be Animations.ResetAnimation.Value/Animations.ResetAnimation.AnimationId or what, because that looks off to me.
Instead of getting the animation tracks using GetPlayingAnimationTracks, why don’t you save the track to a variable or a table and stop it from there? Since everything is indexed, there would be no mystery as to what is being stopped or played.
All you would need to do is determine what animations are played from the table when the tool is equipped/unequipped and reload animations when the humanoid changes. You could probably do this all from a module script to keep it neat and tidy too.
Have you tried adding the tracks to the module so that the module can manage them instead? You could make it so your event functions loop through a table of animation tracks that you can edit.
local AH = Player.AnimationHolder
AH.AnimationId = Animations.ResetAnimation
Player.Character.Humanoid:LoadAnimation(AH):Play()
it may look weird not having and idle animation and reset animation, there could be a possibility that the holding animation is somehow getting played again somewhere. (Oh and is the local script getting disabled before destroying that and stopping the animation?)
A rule that comes from requiring modules is that they run on the datamodel that the requiring script came from. So if you require a module from a local script, then it would have access to client-side instead of server-side.