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)

1 comment
Hi there, thanks for the reply. At first glance it seems to works fine, but when the player unequipped at the wait statement out side the if statement. Then him/she equipped the cup again, it will think equipped equals true and execute the next animation!