I'm not sure if it's a ROBLOX bug, but for the past several weeks I've noticed that if a tool has a function connected by an Equipped event, it will continue to run even after Unequipping the tool. This can cause swords to continue to deal damage and play animations from the Backpack and really any sort of related problem. what could I do to end the Equipped event?
COMMUNITY QUESTION
Disconnecting an onEquipped function?
2 answers
local equippedEvent = tool.Equipped:connect(function()
--stuff
end)
tool.Unequipped:connect(function()
equippedEvent:disconnect()
end)
Alright, this is 3 years late, however, the problem is relevant to a problem I had with my tool. The problem is you have a ---button1down function---- inside the equipped function like:
tool.Equipped:Connect(function()
mouse.Button1Down(function()
print("fire gun")
end)
end)
tool.Unequipped:Connect(function()
end)
However the roblox will continue to call the click function even though equipped to prevent this from happening try this:
equipped = false
tool.Equipped:Connect(function()
equipped = true
print("Equipped")
end)
Mouse.Button1Down:Connect(function()
if equipped == true then
print("Click")
--Weapon Code goes here--
end
end)
tool.Unequipped:Connect(function()
equipped = false
print("Unequipped")
end)
Alright hope this helps someone who comes across this problem.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Hm, I tried that but it still didn't help. It's as if the Unequipped event doesn't always fire.