Help with a button

i’m trying to make a frame/button that becomes invisible and then another frame/button that becomes visible, I got the first part done but I don;t know how to do the second part

local onClicked = script.Parent -- parent of check
local makeVis = script.Parent.Parent.check_box -- what will become visible

onClicked.MouseButton1Click:Connect(function()
	onClicked.Visible = false -- becomes false
	wait(0.01) -- wait before visible
	makeVis.Visible = true -- becomes true
-- trying to make it so if they click again its the oppisite
	onClicked.MouseButton1Click:Connect(function()
		onClicked.Visible = true  -- becomes ttrue
		wait(0.01) -- wait
		makeVis.Visible = false -- becomes false
	end)
end)
2 Likes

You dont need 2 click events at the same time.

You could just do a if statement and tell the script if the ui is visible or not. You also dont really need to add a wait on each click.

if onClicked.visible = true
wait(0.01)
makeVis.visible = false

?

Like @Ok6c said, you don’t need two events. You can use a debounce that’s switched on or off when you click the button. Here’s what it could look like:

local onClicked = script.Parent -- parent of check
local debounce = true
local makeVis = script.Parent.Parent.check_box -- what will become visible

onClicked.MouseButton1Click:Connect(function()
	if(debounce) then
		debounce = false
		onClicked.Visible = false -- becomes false
		wait(0.01) -- wait before visible
		makeVis.Visible = true -- becomes true
	else
		debounce = true
		onClicked.Visible = true  -- becomes ttrue
		wait(0.01) -- wait
		makeVis.Visible = false -- becomes false
	end
end)
1 Like
local onClicked = script.Parent
local makeVis = onClicked.Parent[check_box]

onClicked.MouseButton1Up:Connect(function()
    onClicked.Visible = not onClicked.Visible
    wait()
    makeVis.Visible = not makeVis.Visible
end)

You could say if the button is visible or not, and say then do this, which makes the ui visible

If Frame.Visible == false then
Frame.Visible = true

You can add a else to make a toggle button that can open and close each time a player clicks.

Wouldn’t you want to do something like this?

local onClicked = script.Parent
local makeVis = script.Parent.Parent.check_box
local Clicked = false -- this is to check if they've clicked once or twice

onClicked.MouseButton1Click:Connect(function()
     if not Clicked then
           Clicked = true
           OnClicked.Visible = false
           wait(0.01)
           makeVis.Visible = true
     else
            Clicked = false
            OnClicked.Visible = true
            wait(0.01)
            makeVis.Visible = false
      end
end)

doesn;t work, don’t know how to fix it, i dont want to add another script.

local onClicked = script.Parent -- parent of check
local makeVis = script.Parent.Parent.check_box -- what will become visible

onClicked.MouseButton1Click:Connect(function()
    if makeVis.Visible == false then
        print("Making the Frame visible")
    	onClicked.Visible = false -- becomes false
	    wait(0.01) -- wait before visible
    	makeVis.Visible = true -- becomes true
    elseif makeVis.Visible == true then
        print("Making the Frame invisible")
    	onClicked.Visible = true  -- becomes true
    	wait(0.01) -- wait
    	makeVis.Visible = false -- becomes false
    else
        print("Wut")
    end
end)

Try this?

local onClicked = script.Parent -- parent of check
local makeVis = script.Parent.Parent.check_box -- what will become visible

onClicked.MouseButton1Click:Connect(function()
	onClicked.Visible = false -- becomes false
	wait(0.01) -- wait before visible
	makeVis.Visible = true -- becomes true
else
		onClicked.Visible = true  -- becomes ttrue
		wait(0.01) -- wait
		makeVis.Visible = false -- becomes false
	end)
end)

doesn’t work lol, not even the “wut” comes on.

erorr at else---------------------

try removing the second on clicked

I fixed it, try again :thinking:

nope, it wouldnt go to the second “making the frame vis”

Is onClicked a TextButton/TextBox? and is makeVis a Frame?

1 Like

no, it’s a button.-----------------

local onClicked = script.Parent
local makeVis = script.Parent.Parent.check_box
local isOpen = false

onClicked.MouseButton1Click:Connect(function()
    if not isOpen then
        isOpen = true
        onClicked.Visible = false
        wait(.01)
        makeVis.Visible = true
    if isOpen then
        isOpen = false
        onClicked.Visible = true
        wait(.01)
        makeVis.Visible = false
	end
end)

Is this in a script or localscript? The code will only execute in a localscript.

thanks, i realized it was a button and it wouldn’t work.

1 Like