-
What do you want to achieve? Keep it simple and clear!
I am making a gun that fires. I want an animation to be played when it does so. -
What is the issue? Include screenshots / videos if possible!
After firing for some time, the Output gets filled with “AnimationTrack limit of 256 tracks for one Animator exceeded, new animations will not be played” -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I did, but none of them seem to help.
Here is relevant code:
function ViewModelThingy.AnimationPlay(AnimationName)
local ViewModel = workspace.Camera:FindFirstChild("ViewModel")
local Animator = ViewModel.Humanoid.Animator
if AnimationName == "Idle" then
local AnimationToPlay = ViewModel.Animations:FindFirstChild(AnimationName)
print(AnimationToPlay)
local AnimationTrack = Animator:LoadAnimation(AnimationToPlay)
AnimationTrack.Priority = Enum.AnimationPriority.Action
AnimationTrack:Play()
elseif AnimationName == "Unholster" then
local AnimationToPlay = ViewModel.Animations:FindFirstChild(AnimationName)
print(AnimationToPlay)
local AnimationTrack = Animator:LoadAnimation(AnimationToPlay)
AnimationTrack.Priority = Enum.AnimationPriority.Action
AnimationTrack:Play()
AnimationTrack.Looped = false
AnimationTrack.Stopped:Wait()
else
local CurrentAnimationsPlaying = Animator:GetPlayingAnimationTracks ( )
for i,v in ipairs(CurrentAnimationsPlaying) do
v:Stop()
end
local AnimationToPlay = ViewModel.Animations:FindFirstChild(AnimationName)
print(AnimationToPlay)
local AnimationTrack = Animator:LoadAnimation(AnimationToPlay)
AnimationTrack.Priority = Enum.AnimationPriority.Action
AnimationTrack.Looped = false
AnimationTrack:Play()
AnimationTrack.Stopped:Connect(function()
AnimationToPlay = ViewModel.Animations:FindFirstChild("Idle")
AnimationTrack = Animator:LoadAnimation(AnimationToPlay)
AnimationTrack.Priority = Enum.AnimationPriority.Action
AnimationTrack:Play()
end)
end
end