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?
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)