I have a function in a script that stops a tools animation when it is unequipped but there is a bug
The code:
local plr =
-- code for animations and stuff
function unEquipped()
local drink = plr:FindFirstChild("Humanoid"):LoadAnimation(Tool.drink)
drink:Stop()
local equip = plr:FindFirstChild("Humanoid"):LoadAnimation(Tool.equip)
equip:Stop()
end
script.Parent.Unequipped:Connect(unEquipped)
-- code for animations and stuff
local plr = -- YourPlayer Here
function unEquipped()
local drink = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(Tool.drink)
drink:Stop()
local equip = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(Tool.equip)
equip:Stop()
end
script.Parent.Unequipped:Connect(unEquipped)
local plr = script.Parent.Parent.Parent
function unEquipped()
local plr = script.Parent.Parent.Parent
local drink = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(Tool.drink)
drink:Stop()
local equip = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(Tool.equip)
equip:Stop()
end
script.Parent.Unequipped:Connect(unEquipped)
Might be because you’re loading a new animation (despite it being the same animation) onto the humanoid. Take the original saved animation and use :Stop() on that instead
function unEquipped()
local char = script.Parent.Parent
local drink = char:FindFirstChild("Humanoid"):LoadAnimation(Tool.drink)
drink:Stop()
local equip = char:FindFirstChild("Humanoid"):LoadAnimation(Tool.equip)
equip:Stop()
end
script.Parent.Unequipped:Connect(unEquipped)
local Tool = script.Parent;
local plr = script.Parent.Parent.Parent
local opened = script.Parent.opened
local drink = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(Tool.drink)
local equip = plr.Character:FindFirstChild("Humanoid"):LoadAnimation(Tool.equip)
enabled = true
function onActivated()
if not enabled then
return
end
if opened.Value == true then
enabled = false
Tool.Handle.DrinkSound:Play()
drink:Play()
task.wait(5)
enabled = true
end
end
enabled = true
function onEquipped()
if opened.Value == false then
equip:Play()
Tool.Handle.OpenSound:Play()
task.wait(1)
opened.Value = true
end
end
function unEquipped()
local plr = script.Parent.Parent.Parent
drink:Stop()
equip:Stop()
end
script.Parent.Activated:Connect(onActivated)
script.Parent.Equipped:Connect(onEquipped)
script.Parent.Unequipped:Connect(unEquipped)