AnimationTrack:Stop() is not stopping the animation


I wan’t to stop the animation!


The issue is that the animation doesn’t stop when the script tells it to! print(“B”) prints too!


local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local hum = char:FindFirstChild("Humanoid")

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=18223587617"
animation.Parent = script.Parent



script.Parent.AncestryChanged:Connect(function()
	
if script.Parent.Parent == char then
	print("A")
	
	
	local animtrack = hum:WaitForChild("Animator"):LoadAnimation(animation)
	
	animtrack:Play()
	
end

end)

script.Parent.AncestryChanged:Connect(function()

	if script.Parent.Parent == plr.Backpack then
		print("B")


		local animtrack = hum:WaitForChild("Animator"):LoadAnimation(animation)

		animtrack:Stop()

	end

end)

None of the solutions work…

Hey there, from what i see it’s because each time AncestryChanged function fired, it loads the animation which causing animationTrack:Stop() unavailable.
Here’s the same script, but i tried to rewrite it and explain it here.

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:FindFirstChild("Humanoid")

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=18223587617"
animation.Parent = script.Parent

local animtrack -- 1

script.Parent.AncestryChanged:Connect(function()
    if script.Parent.Parent == char then
        print("A")
        if not animtrack then -- 2
            animtrack = hum:WaitForChild("Animator"):LoadAnimation(animation)
        end
        animtrack:Play()
    elseif script.Parent.Parent == plr.Backpack then
        print("B")
        if animtrack then  
            animtrack:Stop() -- 3
        end
    end
end)
1 Like

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