Tool after unequip playing animation

Hi dev’s, i have issue with my tool. After unequiping tool animation not stoping play.
image

My script:

local par = script.Parent
par.Activated:Connect(function()
	if par.Parent then
		local Humanoid2 = par.Parent:FindFirstChild("Humanoid")
		if Humanoid2 ~= nil then
			local AnimLoaded2 = nil
			AnimLoaded2 = Humanoid2:LoadAnimation(par.Handle.BoomBoxAnim)
			if AnimLoaded2 then
				AnimLoaded2:Play()
				par.Handle.BoomBoxMusic:Play()
				while true do
					if (Humanoid2.MaxHealth > Humanoid2.Health + 5) then
						Humanoid2.Health = Humanoid2.Health + 5
					else	
						Humanoid2.Health = Humanoid2.MaxHealth
					end
					wait(0.5)
				end
			end
		end
	end
end)

par.Unequipped:Connect(function()
	par.Handle.BoomBoxMusic:Stop()
end)

2 Likes

You have to manually stop it

local par = script.Parent
par.Activated:Connect(function()
	if par.Parent then
		local Humanoid2 = par.Parent:FindFirstChild("Humanoid")
		if Humanoid2 ~= nil then
			local AnimLoaded2 = nil
			AnimLoaded2 = Humanoid2:LoadAnimation(par.Handle.BoomBoxAnim)
			if AnimLoaded2 then
				AnimLoaded2:Play()
				par.Handle.BoomBoxMusic:Play()
				while true do
					if (Humanoid2.MaxHealth > Humanoid2.Health + 5) then
						Humanoid2.Health = Humanoid2.Health + 5
					else	
						Humanoid2.Health = Humanoid2.MaxHealth
					end
					wait(0.5)
				end
			end
		end
	end
end)

par.Unequipped:Connect(function()
	par.Handle.BoomBoxMusic:Stop()
    AnimLoaded2:Stop()
end)
1 Like

You didn’t cycle through humanoid.Animator to stop the animation!
Here a quick fix

local character

par.Equipped:Connect(function()
    character = par.Parent
end)

par.Unequipped:Connect(function()
    local anit = character:FindFirstChild("Humanoid"):FindFirstChild("Animator")
    if anit then
       for order, animation in ipairs(anit:GetPlayingAnimationTracks()) do
          animation:Stop()
       end
    end
end)
1 Like

You should define the animation track variable outside of the .Activated event

Try this:

local par = script.Parent
local AnimTrack
par.Activated:Connect(function()
	if par.Parent then
		local Humanoid2 = par.Parent:FindFirstChild("Humanoid")
		if Humanoid2 ~= nil then
			AnimTrack = Humanoid2.Animator:LoadAnimation(par.Handle.BoomBoxAnim)
			if AnimTrack then
				AnimTrack:Play()
				par.Handle.BoomBoxMusic:Play()
				while true do
					if (Humanoid2.MaxHealth > Humanoid2.Health + 5) then
						Humanoid2.Health = Humanoid2.Health + 5
					else	
						Humanoid2.Health = Humanoid2.MaxHealth
					end
					wait(0.5)
				end
			end
		end
	end
end)

par.Unequipped:Connect(function()
	par.Handle.BoomBoxMusic:Stop()
	if AnimTrack then
		AnimTrack:Stop()
		AnimTrack = nil
	end
end)
2 Likes

Thanks, top guy so much! :kissing_heart: :kissing_heart: :kissing_heart:

2 Likes

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