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

How to make a textbutton toggle a Bool Value on/off by clicking it 2 times?

Asked by 4 years ago

Here's what I have, I keep getting error messages.

GotoPlayer.MouseButton1Click:Connect(function()

   BoolV.Value = true 

    else

    BoolV.Value = false

end)

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Hope it'll help you

local a = 0;

local totalclicks = 2

script.Parent.MouseButton1Click:Connect(function()
    if (a < totalclicks) then
        a = a + 1;
        if a == totalclicks and BoolValue == false then
            BoolV.Value = true;
            print("Code executed!");
            a = 0
            -- Code here
        elseif a == totalclicks and BoolValue == true then
            BoolV.Value = false;
            a = 0
        end
    end
end)
Ad
Log in to vote
0
Answered by 4 years ago

Here's a more simpler varient. I believe you want a toggle-able TextButton. Lemme help ya.

local toggle = true
script.Parent.MouseButton1Click:Connect(function()
    if toggle == true then
        toggle = false
        print("Toggle has been switched to false")
    else
        toggle = true
        print("Toggle has been switched to true")
    end
end

I hope I helped! Ask me in the comments if you don't understand anything. Merry Early Christmas!

Answer this question