Need help with my animation (being constantly looped)

local currentAnimation = nil
local isAnimating = false

local function UpdateAnimations(newHealth)

if newHealth == 1 then
downedEffect.Enabled = true
local moveDirection = humanoid.MoveDirection

  if moveDirection.Magnitude <= 0.1 then
  	
  	downedIdleAnimationTrack:Play()
  	downedMovingAnimationTrack:Stop()
  	currentAnimation = downedIdleAnimationTrack
  	isAnimating = true
  else
  	
  	downedMovingAnimationTrack:Play()
  	downedIdleAnimationTrack:Stop()
  	currentAnimation = downedMovingAnimationTrack
  	isAnimating = true
  end

elseif newHealth == 100 then
downedEffect.Enabled = false
downedMovingAnimationTrack:Stop()
downedIdleAnimationTrack:Stop()
local currentAnimation = nil
isAnimating = false
end
end

game:GetService(“RunService”).RenderStepped:Connect(function()
local currentHealth = humanoid.Health

UpdateAnimations(currentHealth)
end)

UpdateAnimations(humanoid.Health)

my “downedMoving” animation keeps looping and I’m having trouble on different methods I could try to use. The animation is supposed to be like this:

But instead it’s constantly getting looped because of the RenderStepped, I tried doing debounce but I don’t know if I’m even doing it right.

There’s a property under animation tracks called IsPlaying. If it’s true, your animation is playing and you don’t need to call :Play() on it again:

if not downedMovingAnimationTrack.IsPlaying then
    downedIdleAnimationTrack:Play()
end

You should do the same for your idle animation as well to save on performance.

1 Like
local currentAnimation = nil
local isAnimating = false

local function UpdateAnimations(newHealth)

if newHealth == 1 then
downedEffect.Enabled = true
local moveDirection = humanoid.MoveDirection

  if moveDirection.Magnitude <= 0.1 then
  	if not downedIdleAnimationTrack.IsPlaying then
  	  	downedIdleAnimationTrack:Play()
  	end
  	downedMovingAnimationTrack:Stop()
  	currentAnimation = downedIdleAnimationTrack
  	isAnimating = true
  else
  	if not downedMovingAnimationTrack.IsPlaying then
  	  	downedMovingAnimationTrack:Play()
  	end
  	downedIdleAnimationTrack:Stop()
  	currentAnimation = downedMovingAnimationTrack
  	isAnimating = true
  end
elseif newHealth == 100 then
downedEffect.Enabled = false
downedMovingAnimationTrack:Stop()
downedIdleAnimationTrack:Stop()
local currentAnimation = nil
isAnimating = false
end
end

game:GetService(“RunService”).RenderStepped:Connect(function()
local currentHealth = humanoid.Health

UpdateAnimations(currentHealth)
end)

UpdateAnimations(humanoid.Health)

Maybe this would work?

1 Like

Try this,

local currentAnimation = nil
local isAnimating = false

local function UpdateAnimations(newHealth)

	if newHealth == 1 then
		downedEffect.Enabled = true
		local moveDirection = humanoid.MoveDirection
		
		
		
		if moveDirection.Magnitude <= 0.1 then
			if not downedIdleAnimationTrack.IsPlaying then
				downedIdleAnimationTrack:Play()
				downedMovingAnimationTrack:Stop()
				currentAnimation = downedIdleAnimationTrack
				isAnimating = true
			end
		else
			
			
			if not downedMovingAnimationTrack.IsPlaying then
				downedMovingAnimationTrack:Play()
				downedIdleAnimationTrack:Stop()
				currentAnimation = downedMovingAnimationTrack
				isAnimating = true
			end
		end
	elseif newHealth == 100 then
		downedEffect.Enabled = false
		downedMovingAnimationTrack:Stop()
		downedIdleAnimationTrack:Stop()
		local currentAnimation = nil
		isAnimating = false
	end
end

game:GetService(“RunService”).RenderStepped:Connect(function()
	local currentHealth = humanoid.Health

	UpdateAnimations(currentHealth)
end)

UpdateAnimations(humanoid.Health)

Basically you need to check to see if the animation is already playing or not, If the animation is playing then it won’t do anything, Else if the animation is NOT playing then it will make the animation play!

I hope this works for you! if not, can you provide where you get the animation tracks and the “downdedEffect”?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.