I've been trying to make an animation for the player when they drink a cup of coffee, but the problem is when the player unequips the cup, the animations for the player are still playing until they are finished. None of my animations are looped. Is there any way to prevent this from happening, any bits of help will be appreciated. Thanks!
local tool = script.Parent.Parent local player = game.Players.LocalPlayer local character = player.Character local drinkAnimation = script.Parent:WaitForChild("drinkingAnimation") local idleAnimation = script.Parent:WaitForChild("idleAnimation") local returnAnimation = script.Parent:WaitForChild("returnAnimation") local drinkAnimationTrack = character.Humanoid:LoadAnimation(drinkAnimation) local idleAnimationTrack = character.Humanoid:LoadAnimation(idleAnimation) local returnAnimationTrack = character.Humanoid:LoadAnimation(returnAnimation) local isDrinking = false tool.Activated:Connect(function() if tool.coffeeWater.Transparency ~= 0 then return end if isDrinking == false then isDrinking = true drinkAnimationTrack:Play() wait(drinkAnimationTrack.Length) idleAnimationTrack:Play() wait(idleAnimationTrack.Length + 2) idleAnimationTrack:Stop() returnAnimationTrack:Play() wait(returnAnimationTrack.Length) returnAnimationTrack:Stop() isDrinking = false end end) tool.Unequipped:Connect(function() drinkAnimationTrack:Stop() idleAnimationTrack:Stop() returnAnimationTrack:Stop() end)
Hi there! its because when you unequip a tool it doesn't stop all code in the activated function meaning if you unequip and there's a wait statement and after that it plays an animation that animation will play
to fix this simply check if the tool is still equipped after each wait statement
Snippet:
If Tool.Equipped then --Code end
Hope this helped.