Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How come my debounce works once then doesnt work anymore?

My script prints 'event fired' when you click with the tool, and fires the event. I added a debounce into the script, but it only works once, then it doesnt work anymore.

local debounce = false
local tool = script.Parent
local rp = game:GetService("ReplicatedStorage")
local push = rp:WaitForChild("Push")


tool.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		if not debounce then
			push:FireServer()
			print'event fired'
			debounce = true
		elseif debounce == true then
			wait(2.5)
			debounce = false
		end
	end)
end)


1 answer

✓ Accepted answer

You dont need to add the elseif.

do this instead:

local debounce = false
local tool = script.Parent
local rp = game:GetService("ReplicatedStorage")
local push = rp:WaitForChild("Push")


tool.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()
        if not debounce then
            debounce = true
            push:FireServer()
            print'event fired'
            wait(2.5)
            debounce = false
        end
    end)
end)

this should work now.

2 comments

0

thanks!

0

no problem! I'm so glad i could help :D

This discussion is preserved as it was. New answers, comments, and votes are closed.