How to stop animation when ending - help

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So i want to stop the animation going back to normal pose roblox

  2. What is the issue? Include screenshots / videos if possible!
    image
    so whenever i click an animation on the gui it should end where it should be but then
    return back to normal pose like in the screenshot and idk how to stop that

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i tried to change priority animations nothing work
    no solution founded just 1

local frame=script.Parent
local user=game.Players.LocalPlayer
repeat wait() until user.Character local char=user.Character
local humanoid=char:WaitForChild("Humanoid")
local anim
function playanim(id)
	if char~=nil and humanoid~=nil then
		local id="rbxassetid://"..tostring(id)
		local oldanim=char:FindFirstChild("LocalAnimation")
		if anim~=nil then
			anim:Stop()
		end
		if oldanim~=nil then
			if oldanim.AnimationId==id then
				oldanim:Destroy()
				return
			end
			oldanim:Destroy()
		end
		local animation=Instance.new("Animation",char)
		animation.Name="LocalAnimation"
		animation.AnimationId=id
		anim=humanoid:LoadAnimation(animation)
		anim:Play()
	end
end
local b1=frame.Button1
b1.MouseButton1Down:connect(function() playanim(b1.AnimID.Value) end)
local b2=frame.Button2
b2.MouseButton1Down:connect(function() playanim(b2.AnimID.Value) end)
local b3=frame.Button3
b3.MouseButton1Down:connect(function() playanim(b3.AnimID.Value) end)
local b4=frame.Button4
b4.MouseButton1Down:connect(function() playanim(b4.AnimID.Value) end)
local b5=frame.Button5
b5.MouseButton1Down:connect(function() playanim(b5.AnimID.Value) end)
local b6=frame.Button6
b6.MouseButton1Down:connect(function() playanim(b6.AnimID.Value) end)

3 Likes

I don’t get you, do you mean you want to stop the animation which the holding animation in the video?

1 Like

wait let me send u an real quick video rn

2 Likes

So as you can see here when i press the animation button sabre salute
the animation doesnt stop where it supposed to be
then it return himself back to normal pose

1 Like

The video i sended when u see the left arm holding down the sabre
its supposed to stop the animation right there
but then it returned himself back to normal pose

so how to stop that?

1 Like

you mean to stop the animation at the end?

1 Like

Yes you can see in the video right there
but then it return back to normal pose
which idk how to stop that

1 Like

You can stop or freeze the animation like this:

animationTrack:AdjustSpeed(0)
1 Like

Which line do i have to add that?

1 Like

Detect if the animation is about to end and stop it with the line i sent you right before the end with very small number (ex. 0.000001)

I found this script and i added the line that stops it:

animationTrack.Stopped:Connect(function()
	animationTrack:Play(0, 1, 0) --Will restart the track at the beginning, fadeIn 0 so it immediately has appropriate weight, speed 0, so that it pauses
	animationTrack.TimePosition = animationTrack.Length --Set to the last key in the sequence
    animationTrack:AdjustSpeed(0)
end)

How to fix this error

so the sabre salute work fine -. the code u gave me
but when i want to return back to normal pose - sabre down
with another animation i clicked

Stop the playing animation, before playing the new one.

Is there a way i can do that without clicking it?

Put this in a function, and call it whenever you want to stop any animations:

for i,v in pairs(player.Character.Humanoid:GetPlayingAnimationTracks()) do
	v:Stop()
end

this stops ALL playing animations on the character.

So if i click the first animation
it will end there
but when i want to click another animation
it will play without a problem?

Yes, just make sure to do as i said above before playing the new one.

sorry where do i put that code in which line again

Yo may i ask where do i put that code at? like which line of the number

Oh Just put it in a function and call it right before calling the animation:Play()

local frame=script.Parent
local user=game.Players.LocalPlayer
repeat wait() until user.Character local char=user.Character
local humanoid=char:WaitForChild("Humanoid")
local anim

function stopanim()
for i,v in pairs(user.Character.Humanoid:GetPlayingAnimationTracks()) do
	v:Stop()
end
end
function playanim(id)
	if char~=nil and humanoid~=nil then
		local id="rbxassetid://"..tostring(id)
		local oldanim=char:FindFirstChild("LocalAnimation")
		if anim~=nil then
			anim:Stop()
		end
		if oldanim~=nil then
			if oldanim.AnimationId==id then
				oldanim:Destroy()
				return
			end
			oldanim:Destroy()
		end
		local animation=Instance.new("Animation",char)
		animation.Name="LocalAnimation"
		animation.AnimationId=id
		anim=humanoid:LoadAnimation(animation)
        stopanim()
		anim:Play()
	end
end
local b1=frame.Button1
b1.MouseButton1Down:connect(function() playanim(b1.AnimID.Value) end)
local b2=frame.Button2
b2.MouseButton1Down:connect(function() playanim(b2.AnimID.Value) end)
local b3=frame.Button3
b3.MouseButton1Down:connect(function() playanim(b3.AnimID.Value) end)
local b4=frame.Button4
b4.MouseButton1Down:connect(function() playanim(b4.AnimID.Value) end)
local b5=frame.Button5
b5.MouseButton1Down:connect(function() playanim(b5.AnimID.Value) end)
local b6=frame.Button6
b6.MouseButton1Down:connect(function() playanim(b6.AnimID.Value) end)

The code you gave me it didnt work the animations anymore to play