Animation Issue

I need the animation to end once the tool is unequipped or deactivated

The Issue Is that I cannot end the animation once it is unequipped ( I am stuck in the animation when the tool is unequipped)


tool = script.Parent
handle = tool:WaitForChild("Handle")

tool.Equipped:Connect(function()
	local Character = tool.Parent.Parent
	local nameanim = Instance.new("Animation")
	nameanim.AnimationId = "http://www.roblox.com/Asset/?ID=7987510654"
	local name = Character.Humanoid:LoadAnimation(nameanim)

	name:Stop()


	tool.Handle.Roar1.Enabled = false
	tool.Handle.Roar2.Enabled = false
	print("Tool was enabled")

	
	
end)


tool.Activated:Connect(function()
	local Character = tool.Parent
	local nameanim = Instance.new("Animation")
	nameanim.AnimationId = "http://www.roblox.com/Asset/?ID=7987510654"
	local name = Character.Humanoid:LoadAnimation(nameanim)
	
	name:Play()
	 
	tool.Handle.Roar:Play()
	tool.Handle.Roar1.Enabled = true
	tool.Handle.Roar2.Enabled = true
	wait(10.8)
	
	print("Tool has been clicked")
	name:Stop()
	tool.Handle.Roar1.Enabled = false
	tool.Handle.Roar2.Enabled = false
end)

------------------------------------------------
tool.Deactivated:Connect(function()
	local Character = tool.Parent.Parent
	local nameanim = Instance.new("Animation")
	nameanim.AnimationId = "http://www.roblox.com/Asset/?ID=7987510654"
	local name = Character.Humanoid:LoadAnimation(nameanim)

	name:Stop()

	tool.Handle.Roar1.Enabled = false
	tool.Handle.Roar2.Enabled = false
	print("Tool has been Stopped")



end)



tool.Unequipped:Connect(function()
	local Character = tool.Parent.Parent.Parent.Parent.LocalPlayer
	local nameanim = Instance.new("Animation")
	nameanim.AnimationId = "http://www.roblox.com/Asset/?ID=7987510654"
	local name = Character.Humanoid:LoadAnimation(nameanim)

	name:Stop()
	
	tool.Handle.Roar2.Enabled = false
	tool.Handle.Roar1.Enabled = false
	

	print("Tool was Unenabled")
 


end)
tool = script.Parent
handle = tool:WaitForChild("Handle")
local name = nil


tool.Equipped:Connect(function()
	local Character = tool.Parent.Parent
	
	if name ~= nil then
		name:Stop()
		name = nil
	end	


	tool.Handle.Roar1.Enabled = false
	tool.Handle.Roar2.Enabled = false
	print("Tool was enabled")



end)


tool.Activated:Connect(function()
	local Character = tool.Parent
	local nameanim = Instance.new("Animation")
	nameanim.AnimationId = "http://www.roblox.com/Asset/?ID=7987510654"
	name = Character.Humanoid:LoadAnimation(nameanim)

	name:Play()

	tool.Handle.Roar:Play()
	tool.Handle.Roar1.Enabled = true
	tool.Handle.Roar2.Enabled = true
	wait(10.8)

	print("Tool has been clicked")
	name:Stop()
	tool.Handle.Roar1.Enabled = false
	tool.Handle.Roar2.Enabled = false
end)

------------------------------------------------
tool.Deactivated:Connect(function()
	local Character = tool.Parent.Parent
	
	if name ~= nil then
		name:Stop()
		name = nil
	end	

	tool.Handle.Roar1.Enabled = false
	tool.Handle.Roar2.Enabled = false
	print("Tool has been Stopped")



end)



tool.Unequipped:Connect(function()
	local Character = tool.Parent.Parent.Parent.Parent.LocalPlayer
	
	if name ~= nil then
		name:Stop()
		name = nil
	end	

	tool.Handle.Roar2.Enabled = false
	tool.Handle.Roar1.Enabled = false


	print("Tool was Unenabled")



end)

You’re loading the same animation each time anything happens to the tool, so stopping the new animation won’t do anything. Load the animation once at the start of the script and use only name:Play() and name:Stop() when activated or deactivated.

1 Like

I agree with @B0R2DDD. Do what he said to do. It load it once.

I actually love you so much thank you

local players = game:GetService("Players")
local player = script:FindFirstAncestorWhichIsA("Player") or players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local nameAnim = Instance.new("Animation")
nameAnim.AnimationId = "http://www.roblox.com/Asset/?ID=7987510654"
local name = animator:LoadAnimation(nameAnim)

local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local roar = handle:WaitForChild("Roar")
local roar1 = handle:WaitForChild("Roar1")
local roar2 = handle:WaitForChild("Roar2")

tool.Equipped:Connect(function()
	name:Stop()
	roar1.Enabled = false
	roar2.Enabled = false
end)

tool.Unequipped:Connect(function()
	name:Stop()
	roar1.Enabled = false
	roar2.Enabled = false
end)

tool.Activated:Connect(function()
	name:Play()
	roar:Play()
	roar1.Enabled = true
	roar2.Enabled = true
	task.wait(10.8)
	name:Stop()
	roar1.Enabled = false
	roar2.Enabled = false
end)

tool.Deactivated:Connect(function()
	name:Stop()
	roar1.Enabled = false
	roar2.Enabled = false
end)

Yeah, I’m really not sure why the original poster was creating an entirely new “AnimationTrack” instance each time one of the 4 events was fired.

2 Likes