How do I change something twice using MouseButton1Click?

My goal: is to make a graphics button, currently, I’m using some demo code, so I’m just trying to get the mouse button to change it to something different like “low” and “high” every click.

my code: GraphicsButton.MouseButton1Click:Connect(function() blueffect.Enabled = false GraphicsButton.Text = "Low" end)

I can only do it once, how do I change it again if a player wants to change it back to high?
I’m going to guess the answer is very simple, but I just don’t know it.

3 Likes

Use an if statement, like this:

GraphicsButton.MouseButton1Click:Connect(function() 
     if GraphicsButton.Text=="High" then
          blueffect.Enabled = false 
          GraphicsButton.Text = "Low" end)
     else
          blueffect.Enabled = true
          GraphicsButton.Text = "High" end)
end)

have you tried making a toggle?
smthn like this:

local Toggle = false

GraphicsButton.MouseButton1Click:Connect(function()
    if not Toggle then
       Toggle = true
       blueffect.Enabled = true
       GraphicsButton.Text = "high"
    end
    if Toggle then
        Toggle = false
        blueffect.Enabled = false
        GraphicsButton.Text = "low"
    end
end)

bit of a new scripter but it might work :thinking:

1 Like

basically what everyone else did but more shorter.

local isLow = true

GraphicsButton.MouseButton1Click:Connect(function()
    isLow = not isLow
    
    if isLow == false then
        blueeffect.Enabled = false
        GraphicsButton.Text = "Low"
    else
        blueeffect.Enabled = true
        GraphicsButton.Text = "High"
    end
end)
2 Likes

Just an FYI, that toggle won’t work. You need to use an else or elseif in that situation. When you run that, it will see that Toggle is false, then it will set Toggle to true, then the next if statement will check and see that Toggle is true, and it will run that part aswell.

1 Like

good to know! ty for telling me before I give out more bad advice :sweat_smile:

1 Like