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

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

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

GotoPlayer.MouseButton1Click:Connect(function()

   BoolV.Value = true 

	else

	BoolV.Value = false
	
end)

2 answers

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)

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!

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