hey, I was making a tool ability today, but I realized that if you deactivate the tool from another line it will fire the Tool.Deactivated event twice if you release your finger off your mouse. Is there any way to fix this?
source code:
local tool = script.Parent
local enabled = false
local start = nil
local duration = 3
tool.Activated:Connect(function()
print "activated"
enabled = true
start = os.clock()
while enabled == true do
if os.clock() - start >= duration then
tool:Deactivate()
end
end
end
tool.Deactivated:Connect(function()
print "deactivated"
end)
If you have any solutions, please share! Thanks in advance
hey, I wanted to jump back on this, it’s not really working with debounce, because if I use the :Deactivate() method on the tool while the player is still holding it, they can keep holding it until the debounce is finished and then released, therefore triggering the .Deactivated event.
Yes, you can fix this issue by adding a check inside the while loop of your Activated event callback, to see if the tool is still enabled before calling Deactivate(). You can do this by adding a new if statement inside the while block, like this:
while enabled == true do
if os.clock() - start >= duration then
if enabled == true then
tool:Deactivate()
end
end
end