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

Scripts Can't false the bool value?

local Tool = script.Parent
local Mouse = game.Players.LocalPlayer:GetMouse()

debounce = false
waitDealy = 5
Tool.Activated:Connect(function()
	if Tool.Equipped then
		if Mouse.Target and Mouse.Target:FindFirstChild("ClickDetector") then 
			if (Tool.Handle.Position - Mouse.Target.Position).Magnitude <= Mouse.Target.ClickDetector.MaxActivationDistance then
				if not debounce then
					debounce = true
					local plr = game.Players.LocalPlayer
					plr.Wood.Value = plr.Wood.Value + 1
				end
			end
		end
	end
end)

Tool.Deactivated:Connect(function()
	if Tool.Equipped then
		if debounce then
			wait(waitDealy)
			
			debounce = false
		end
	end
end)

my script cant false debounce how to fix it?

1 answer

✓ Accepted answer

Fixed Script:

local Tool = script.Parent
local Mouse = game.Players.LocalPlayer:GetMouse()

debounce = false
waitDealy = 5
Tool.Activated:Connect(function()
    if Tool.Equipped then
        if Mouse.Target and Mouse.Target:FindFirstChild("ClickDetector") then 
            if (Tool.Handle.Position - Mouse.Target.Position).Magnitude <= Mouse.Target.ClickDetector.MaxActivationDistance then
                if not debounce then
                    debounce = true
                    local plr = game.Players.LocalPlayer
                    plr.Wood.Value = plr.Wood.Value + 1
wait(waitDealy)
debounce = false
                end
            end
        end
    end
end)

Mistake:

local Tool = script.Parent
local Mouse = game.Players.LocalPlayer:GetMouse()

debounce = false
waitDealy = 5
Tool.Activated:Connect(function() -- activated means one click
    if Tool.Equipped then
        if Mouse.Target and Mouse.Target:FindFirstChild("ClickDetector") then 
            if (Tool.Handle.Position - Mouse.Target.Position).Magnitude <= Mouse.Target.ClickDetector.MaxActivationDistance then
                if not debounce then
                    debounce = true -- when you click the tool debounce = true
                    local plr = game.Players.LocalPlayer
                    plr.Wood.Value = plr.Wood.Value + 1
                end
            end
        end
    end
end)

Tool.Deactivated:Connect(function() -- deactivated means when left mouse is already down and gets released
    if Tool.Equipped then
        if debounce then -- debounce = true because of .Activated function so it wont run
            wait(waitDealy)

            debounce = false
        end
    end
end)

The solution is to remove the Deactivated Function, because you can only have the Activated Function to make a debounce.

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