Hi dev’s, i have issue with my tool. After unequiping tool animation not stoping play.
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)
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)
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)
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)