Need help with playing animations

So what i have here is 2 animations.

What i want is that when u click the first animations plays. when u click again the second one plays. and so on and on like 1,2,1,2,1,2,12

I tried creating this block of code for it, however it still only plays the first animation?. Anyone can help me with this?

script.Parent.Activated:Connect(function()
	
	local animation1 = script.Animation1
	local animation2 = script.Animation2
	local humanoid = script.Parent.Parent.Humanoid
	
	local animationtrack1 = humanoid:LoadAnimation(animation1)
	local animationtrack2 = humanoid:LoadAnimation(animation2)
	
	local t = 1
	
		if t == 1 then
			animationtrack1:Play()
			t = 2
		elseif t == 2 then
			animationtrack2:Play()
			t = 1
			
		end
	end)
  1. Use true and false for the values
  2. You’re reassigning t to 1 every time you activate it. Move the local t = 1 outside of the function.
2 Likes

Thanks! such a simple solution that i just didnt think off :sweat_smile:

1 Like