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

Why isn't this debounce turn into false?

I want to make a tool that when you click its set as true and starts spamming bricks but when clicked again it's set to false and has to be clicked again to be set as true again.

I don't understand why it isn't working(Line 29),every time I click it displays as true but never as false when I click again,why?

---------------Vairbles---------------
local Tool = script.Parent
local Handle = script.Parent.Handle
local Player = game.Players.LocalPlayer--Gets LocalPlayer(which is the player with tool or script)
local PlayersMouse = Player:GetMouse()--Gets the Players mouse with the GetMouse() method
local Clicked = false
---------Equiped Function----------
    Tool.Equipped:connect(function(Mouse)
------------Coroutine.create---------------
ClickDectector = coroutine.create(function()
        Mouse.Button1Down:connect(function()
            Mouse.Move:connect(function()
                local Distance = (Mouse.Origin.p - Player.Character.Torso.Position).magnitude
                print("Distance From Player:"..Distance)
                if Distance > 21  then
                    local Part = Instance.new("Part",game.workspace)
                    	Part.CFrame = CFrame.new(Mouse.Origin.p)
                    Handle.BrickColor= BrickColor.new("Bright green")
                else
                    print("Nope,Nope,no bricks for you")
                    Handle.BrickColor = BrickColor.new("Bright red")
                end
            end)
		end)
    end)
--------------------------------------------
Mouse.Button1Down:connect(function()
    Clicked = true
    if not Clicked then
	---False statement
	print("Clicked is currently :",Clicked,"in other words Off.")
        Handle.BrickColor = BrickColor.new("Meduim stone grey")
        coroutine.yield(ClickDectector)
		Clicked = false
    else
	---True statement
		print("Clicked is currently :",Clicked,"in other words On.")
        coroutine.resume(ClickDectector)
    end
end)
end)

1 answer

You are setting Clicked to true every time you click because:

Mouse.Button1Down:connect(function()
    Clicked = true
    if not Clicked then

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