Looped animation isn't looping

Animations are loaded only once.

This is the PlayAnimation script

local function PlayAnimation (AnimationName,Looped)
		local AnimationObject:AnimationTrack = Animations[AnimationName]
		
		if not LastAnimation then
			LastAnimation = AnimationObject
			AnimationObject.Looped = Looped
			AnimationObject.Priority = Enum.AnimationPriority.Action
			AnimationObject:Play()
			return
		end
		
		print(LastAnimation,AnimationObject)
		print(AnimationObject == LastAnimation and LastAnimation.IsPlaying)
		
		if (AnimationObject == LastAnimation and LastAnimation.IsPlaying) or not AnimationObject then
			return
		end
		
		LastAnimation:Stop()
		LastAnimation.TimePosition = 0
		
		AnimationObject.Looped = Looped
		AnimationObject.Priority = Enum.AnimationPriority.Action
		AnimationObject:Play()

		LastAnimation = AnimationObject
	end

LastAnimation is a nil from start

The function should stop the previous animation and play the new one.
Instead it plays animation only once.

1 Like

Could it be that you are using:
Humanoid:LoadAnimation()

but that is depreciated; instead you should use:
Animator:LoadAnimation()

https://developer.roblox.com/en-us/api-reference/function/Animator/LoadAnimation

1 Like

Load the animation to the humanoid’s animator, since loading it into the Humanoid is deprecated.

1 Like

Animations don’t replicate to the client properly now.
Turns out looped animations don’t work, well I fixed the issue.