I want my Animation to Stop at the End

What do you want to achieve?
My animation makes a hand go up. When I play the animation, my hand goes up, but then it goes down, wich I don’t want.

Video:

  • Animation isn’t looped
  • Animation is on Idle, if I do it on action it does the same.
  • Animation is exactly 1 second long

Code:

-- // Variables
local plr = game:GetService("Players").LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local armAnimation = game:GetService("ReplicatedStorage").Animations.ArmUpArmDown
local animator = humanoid:WaitForChild("Animator")
local track = animator:LoadAnimation(armAnimation)



-- // Main Function
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
	
	-- Check if E is pressed
	if gameProcessed then return end
	if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
	if input.KeyCode ~= Enum.KeyCode.E then return end
	
	
	print("Pressed E")
	
	track:Play() -- Play the Animation
	
end)
3 Likes

After the animation ends, there is nothing to tell the game to keep the hand up, so it returns to its default position

3 Likes

keep it looped and then manually stop

2 Likes

So I make 2 Animations?

One Animation for making the arm go up.
And the other for looping it and keeping the arm always up.

Right?

3 Likes

1. Ensure the Animation Doesn’t Loop:

It sounds like the animation might be looping back to its starting position, causing the hand to go back down. You mentioned that the animation is not looped, but it’s worth double-checking the animation properties to ensure that it doesn’t loop.

In Roblox Studio, when you create or edit animations, ensure that the Looped property of the animation is unchecked:

  • Go to the animation in ReplicatedStorage.
  • Click on the animation and check the Looped property in the Properties panel.
  • Make sure it’s set to false.

If the animation is being loaded correctly and it’s still looping, ensure the following:

2. Modify the Code to Stop the Animation After Playing:

Even if the animation is not looped, Roblox animations by default will return to their initial state once they are completed, causing the “down” movement. One way to handle this is by using the Stop() function after the animation finishes.

You can stop the animation at the exact moment it finishes by using the track.Stopped event.

Here’s how you can modify your code to stop the animation immediately after it plays:

Copiar código

-- // Variables
local plr = game:GetService("Players").LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local armAnimation = game:GetService("ReplicatedStorage").Animations.ArmUpArmDown
local animator = humanoid:WaitForChild("Animator")
local track = animator:LoadAnimation(armAnimation)

-- // Main Function
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
	
	-- Check if E is pressed
	if gameProcessed then return end
	if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
	if input.KeyCode ~= Enum.KeyCode.E then return end
	
	print("Pressed E")
	
	track:Play() -- Play the Animation

	-- Stop the animation once it's done to prevent it from going down
	track.Stopped:Connect(function()
		track:Stop()
	end)
end)

3. Adjust the Animation Itself:

If the above solution doesn’t work as expected, the issue might be in the animation itself. Check if the animation has a “down” movement included at the end, which causes the hand to return to its original position.

You can modify the animation directly in Roblox Studio using the Animation Editor:

  • Open the Animation Editor.
  • Locate your animation (e.g., ArmUpArmDown).
  • Make sure the keyframe for the “up” position is the last keyframe, and that there’s no keyframe causing it to go back down.
  • Save the changes and upload the new animation.

4. Consider Using a Custom Animation for the “Up” Movement:

If the current animation includes both the “up” and “down” movements, consider splitting them into two separate animations:

  • One animation that raises the hand (without any downward movement).
  • Another animation that returns the hand to the idle position (if needed).

You can then trigger these animations independently depending on the actions of the player.

Example of Playing Separate Animations:

Copiar código

-- // Variables
local plr = game:GetService("Players").LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local armUpAnimation = game:GetService("ReplicatedStorage").Animations.ArmUp
local armDownAnimation = game:GetService("ReplicatedStorage").Animations.ArmDown
local animator = humanoid:WaitForChild("Animator")

local trackUp = animator:LoadAnimation(armUpAnimation)
local trackDown = animator:LoadAnimation(armDownAnimation)

-- // Main Function
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
	
	-- Check if E is pressed
	if gameProcessed then return end
	if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
	if input.KeyCode ~= Enum.KeyCode.E then return end
	
	print("Pressed E")
	
	trackUp:Play() -- Play the "Arm Up" animation
end)

This way, you can ensure the hand only goes up and doesn’t return down unless you specifically play the “ArmDown” animation later.

Conclusion:

To fix the issue, try:

  • Ensuring the animation is not looped in Roblox Studio.
  • Stopping the animation after it finishes using the Stopped event.
  • If needed, split the “up” and “down” actions into separate animations for more control.

Let me know if you need further clarification or adjustments!

2 Likes

nope no need you can just have one animation and make it looped and in script when u want it to go down you can do track:Stop()

2 Likes

Hi! All you need to do, is just add this:

	task.wait(track.Length-0.05)
	track:AdjustSpeed(0)

After track:Play()
If this don’t work, change -0.05 to some bigger value

1 Like
  1. Ensure the Animation Doesn’t Loop:
    I checked and it wasnt Looped like I said

  2. Modify the Code to Stop the Animation After Playing:
    Didn’t worked, the character still goes back to the original Position.
    I also did a print statement to check if the .Stopped Event really fires, it does.

  3. Adjust the Animation Itself:
    The Animation does not have a “down” movement, it only goes up.
    The last keyframe is where the hand is “up”.

  4. Consider Using a Custom Animation for the “Up” Movement:
    Doesnt work too, when I play the trackUp, the character goes to the standart Position.

It works,
When I Press E, my hand is up, but I dont have that animation from hand down to hand up.
Like it instantly does the hand up, but without animation.

Yo it worked,
It does the animation, my hand goes slowly up,
and it STAYS there too! Thanks man.