initially when unequipping the tool it prints “a” once, but unequipping it again makes it print “a” twice, and so on because of the unequip event being in an another event
my question here is how do i make it fire once without making significant changes to the script
local tool = script.Parent
local animScript = nil
local EQUIPPED = false
tool.Equipped:Connect(function()
if EQUIPPED == false then
EQUIPPED = true
local ANIMATION = tool.Parent:WaitForChild(“Humanoid”):LoadAnimation(tool:WaitForChild(“Animation”))
ANIMATION:Play()
print(“equipped”)
Put the Unequipped event outside of the Equipped event and change some of t he code around
Should look like this
local tool = script.Parent
local animScript = nil
local EQUIPPED = false
local ANIMATION
tool.Equipped:Connect(function()
if EQUIPPED == false then
EQUIPPED = true
if not ANIMATION then
ANIMATION = tool.Parent:WaitForChild("Humanoid"):LoadAnimation(tool:WaitForChild("Animation"))
end
ANIMATION:Play()
print("equipped")
end
end)
tool.Unequipped:Connect(function()
EQUIPPED = false
ANIMATION:Stop()
print("a")
end)