Equip animation is extremely glitchy

Equip animation is extremely glitchy

Equipping animation works fine (it doesn’t look great) the first time i equip the knife, but the more I do it it’s like it reduces the animations duration or something

I am making a fps framework (my first attempt atleast) and I am trying to figure out animations, I am currently working on the melee or knife because it’s the easiest to animate.

Video and code blocks below

-- melee
UIS.InputBegan:Connect(function(input, _)
	if input.KeyCode == Enum.KeyCode.Three then
		
		
		if currentViewmodel == secondary or currentViewmodel == primary then
			secondary.Parent = viewmodelDirectory
			primary.Parent = viewmodelDirectory
			melee.Parent = camera
			currentViewmodel = melee
			print("swapping to melee")
			
			sounds.equip:Play()
		else
			melee.Parent = camera
			currentViewmodel = melee
			print("swapping to melee")
			
			sounds.equip:Play()
		end
		-- animation stuff 
		local currentViewmodelAnimations = currentViewmodel:WaitForChild("AnimationController")

		-- equip
		local meleeEquip = currentViewmodelAnimations:WaitForChild("Equip")
		local equipTrack = currentViewmodelAnimations:LoadAnimation(meleeEquip)

		-- idle
		local meleeIdle = currentViewmodelAnimations:WaitForChild("Idle")
		local idleTrack = currentViewmodelAnimations:LoadAnimation(meleeIdle)

		equipTrack:Play()
		
		equipTrack.Ended:Connect(function()
			idleTrack:Play()
			print("equipping anim done")
		end)
	end
end)

any help is appreciated

1 Like

You’re creating a new animation track whenever the tool is equipped

You should only load an animation once and then play it

local equipTrack = currentViewmodelAnimations:LoadAnimation(meleeEquip)
local idleTrack = currentViewmodelAnimations:LoadAnimation(meleeIdle)

You should also change

equipTrack.Ended:Connect(function()

to use :Once() instead of :Connect()

2 Likes

i changed it to :Once() instead of :Connect() but im not sure what you mean by loading it once, could you explain how i’d only load it once and play it?

thanks

1 Like

i think whats happening is that everytime u equip, the anim stacks, so uh try checking if its playing first then stopping it

2 Likes
local equipTrack = currentViewmodelAnimations:LoadAnimation(meleeEquip)
local idleTrack = currentViewmodelAnimations:LoadAnimation(meleeIdle)

This makes a new animation track; you only want 1 per animation, so you can’t create new ones