How do I make this animation stop looping?

There’s this big issue I keep encountering with my NPCs having looped animations for no reason ever since Humanoid:LoadAnimation() became decrepated. Any reasons?

My code:

		local function PlayAnimation(obj, animid)
			local human = (obj and obj:IsA"Humanoid" and obj) or obj:FindFirstChildOfClass"Humanoid"
			
			if not human then
				warn("Cannot play animation in "..obj:GetFullName())
			else
				local animator = human:FindFirstChildOfClass"Animator"
				
				local anim = Instance.new("Animation")
				anim.AnimationId = animid
				
				if not animator then
					animator = Instance.new("Animator", human)
				end
				
				local animtrack = animator:LoadAnimation(anim)
				
				if animtrack then
					animtrack.Priority = Enum.AnimationPriority.Core
					animtrack:Play()
				end
			end
		end

Did you have animation looped set to true when you published it?

How do I do that? I use the Roblox animator plugin…

There should be a a box there if it’s looped or not.

image

1 Like

I just figured out about KeyframeSequence.Looped. Yes, I realized this setting was set to true.

That works as well, too. Thanks! I see what that toggle animation button do.

1 Like