Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Disconnecting an onEquipped function?

Asked by 10 years ago

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?

2 answers

Log in to vote
0
Answered by
MrFlimsy 345 Moderation Voter
10 years ago
local equippedEvent = tool.Equipped:connect(function()
    --stuff
end)

tool.Unequipped:connect(function()
    equippedEvent:disconnect()
end)
0
Hm, I tried that but it still didn't help. It's as if the Unequipped event doesn't always fire. deaththerapy 60 — 10y
Ad
Log in to vote
0
Answered by 6 years ago

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.

Answer this question