You can use a bool value (true/false) to determine if the button is in the on or off state. and then use an if statement to determine how the button should respond to a click.
local activated = false
local function onClicked()
if activated == false then
script.Parent.BrickColor = BrickColor.new("Really red")
else
--Other color state goes here
end
activated = not activated --True will be false & false will be true. This will be used to flip between the two states.
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
Have a simple variable (boolean) and toggle it. If the first time it’s false, set it to green and if it isn’t false, set it to green.
Word of advice: Use local functions ( So that it’s on the stack, (stacks are faster than global environments )) and stay away from deprecated functions.
local debounce = false
local function onClicked()
if debounce then
script.Parent.BrickColor = BrickColor.new("BrightRed")
else
script.Parent.BrickColor = BrickColor.new("Forest Green")
end
debounce = not debounce -- not is the opposite
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked)