Checking if a player clicks a text button again?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want the text button to do something else after being clicked a second time

  2. What is the issue? I’m not sure how to do something else when the text button is clicked a second time

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I have tried loops and just a event and none of that worked

Hello so i’m making a on/off gui switch and i’m trying to do something else once the player clicked the text button again but i’m unsure how

this is what i tried so far

local Button = script.Parent
local Sky = game.Lighting.Sky

Button.MouseButton1Click:Connect(function(Clicked)
    if Clicked then
        Sky:Destroy()
        -- disable the skybox
    else
        if Clicked then
            Sky:Clone()
            Sky.Parent = Sky
            -- enable the sky box again
        end
    end
end)

if its a textbutton you should use the .Avtivated event. with this event there are two arguments if i recall

the input object
and the click number (how many times a player clicked the button)

so with this you can do some like detecting how many times the player clicked, and if they clicked twice you can either enable or disable the skybox

button.Activated:Connect(function(input, clickCount)
   if clickCount == 2 then
     if skybox then
       skybox:Destroy()
     else
       skybox:Clone()
     end
  end
end)

either that or you could add a count maybe

locla count = 1
button.Activated:Connect(function(input, clickCount)
    if count == 1 then
      count = 2
      --do stuff
   else
       count = 1
       --do stuff
    end
end)

https://developer.roblox.com/en-us/api-reference/event/GuiButton/Activated
hope this helps!

local Button = script.Parent
local Sky = game.Lighting.Sky
local SkyEnabled = true

Button.MouseButton1Click:Connect(function()
    SkyEnabled = not SkyEnabled
    Sky.Parent = SkyEnabled and game.Lighting or nil
end)
local Button = script.Parent
local Sky = game.Lighting.Sky

local Clicks = 0

Button.MouseButton1Click:Connect(function(Clicked)
    Clicks += 1
    if Clicks == 1 then
        Sky:Destroy()
        -- disable the skybox
    end
    if Clicks == 2 then
        Sky:Clone()
        Sky.Parent = Sky
        -- enable the sky box again
        Clicks = 0
    end
end)

I hope this works for you. Because it works for me.

In addition to what others said above,

I’d suggest you to make a variable , like this :

local clicks = 0

And, for each click the player clicks on the button, do:
clicks += 1

And with that, you could check how many times he has clicked on the button.