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

How do I make a button that changes every time you click?

I made button where you press brick and then it shows surface box, but when you click it again it doesn't show it anymore. Here's my script:

local isOn = false

function onClicked() 
	isOn = true
	script.Parent.SelectionBox.Visible = true
	script.Parent.SelectionBox.Color3 = Color3.new(255,0,0)
end
function offClicked()
	isOn = false
	script.Parent.SelectionBox.Visible = false
	script.Parent.SelectionBox.Color3 = Color3.new(0,0,0)
end
	script.Parent.ClickDetector.MouseClick:connect(onClicked)
	
	offClicked()

For some reason, when I click it, it shows everything I need but when I click it again, it doesn't turn off like I want it too. Why?

1 answer

✓ Accepted answer

You have the event ClickDetector.MouseClick connected to the function onClicked but no event connected to function offClicked

You could maybe combine them with your "isOn" boolean value

local isOn = false

function onClicked()
	if not isOn then
		isOn = true
		script.Parent.SelectionBox.Visible = true
		script.Parent.SelectionBox.Color3 = Color3.new(255,0,0)
	else
		isOn = false
		script.Parent.SelectionBox.Visible = false
		script.Parent.SelectionBox.Color3 = Color3.new(0,0,0)
	end
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

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