What do you want to achieve?
Print “Unequipped” when a tool is unequipped and stop playing an animation.
What is the issue?
When the tool is equipped, it prints
But whenever it’s unequipped it doesn’t print anything.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried printing directly after connecting to unequipped.
The tool should play an animation when its equipped, which it does and stop the animation when unequipped, which it doesn’t do.
local function OnEquip()
Equipped = true
local Character = Elixir.Parent
if Character then
local Humanoid = Character:WaitForChild("Humanoid")
if Humanoid then
local CustomAnimator = Humanoid:WaitForChild("CustomAnimator")
if CustomAnimator then
if not LoadedAnimation then
LoadedAnimation = CustomAnimator:LoadAnimation(PotionHoldAnimation)
end
LoadedAnimation:Play()
end
end
end
end
local function OnUnequip()
Equipped = false
if LoadedAnimation then
LoadedAnimation:Stop()
end
end
Elixir.Equipped:Connect(function()
print("Equipped.")
OnEquip()
end)
Elixir.Unequipped:Connect(function()
print("Unequipped.")
OnUnequip()
end)
The LoadedAnimation variable is defined at the top of the script.
I don’t understand the issue, your code is fine at first glance, and also the screenshot you provided shows it printing unequipped. Either there’s an issue somewhere else that you didn’t provide in this snippet or the issue is something else entirely that you aren’t describing since there’s nothing obvious that would make this not functional.