Why i can found "Cancel" & How make Cancel then click Icon show GUI only one click?

So i want make Click Icon Show another UI with UI Cancel but if i click Cancel instead Icon, i need to click Icon Double time.


robloxapp-20240416-2134037.wmv (973.8 KB)
Video Showcase what is Problem

local ACHIEVEMENTS = script.Parent.Parent.Parent.GUI1
local Cancel = script.Can
local open = true
script.Parent.MouseButton1Click:Connect(function()
    if open == true then
        open = false
        ACHIEVEMENTS:TweenPosition(UDim2.new(0.32, 0,0.134, 0), "InOut", "Quad", 0.5, true)
        task.wait(0.5)
        ACHIEVEMENTS.Visible = true
    else
        open = true
        ACHIEVEMENTS:TweenPosition(UDim2.new(0.32, 0,1, 0), "InOut", "Quad", 0.5, true)
        ACHIEVEMENTS.Visible = true
    end
end)

I want make LocalScript “Cancel” use then LocalScript “AnotherGUI” Just Click only click one and will Show GUI

Thank you Ya’ll!

I dont really understand what you want to achieve or what issue you have, can you please elaborate on one thing at a time

Well my problem is When i click the Icon it show GUI but if i click Cancel instead of Icon it close UI but if i click Icon again is nothing and i click again is show GUI

So i need how i can make Cancel and Click Icon it will Show only 1 click

Also i can close GUI with Icon too btw

Sorry about the mismatched title

from what I understand, you are using variables to detect if the gui is open or closed, and I see that for Icon there is nothing there so I suppose that its in another script, that means that the gui is open for ICON and when you click CLOSE it wil be closed for CLOSE but still open for ICON, when you click ICON it will now close but it was already closed, then when you click again then it will open, thats why you should make one script, not many parts of it, or use a shared variable like (Visible, Position, or attributes)

Shouldn’t it be ACHIEVEMENTS.Visible = false? Currently it’s being set to true twice

You need to set open = false when the Cancel button is clicked.

ACHIEVEMENTS:FindFirstChild("CANCEL").MouseButton1Click:Connect(function()
   open = false    
 ACHIEVEMENTS:TweenPosition(UDim2.new(0.32, 0,1, 0), "InOut", "Quad", 0.5, true)
   task.wait(0.5)
   ACHIEVEMENTS.Visible = false
end)
1 Like

I want make Visible but not like Invisible and Visible

The Thing is I can’t found local Cancel

Based on the explorer, it should be ACHIEVEMENTS:FindFirstChild("CANCEL").MouseButton1Click.

1 Like

If you always want the Gui to be Visible then both lines are unnecessary, since the Visible property is normally already set to true. This will work the same as your current code:

local ACHIEVEMENTS = script.Parent.Parent.Parent.GUI1
--local Cancel = script.Can
local open = true
script.Parent.MouseButton1Click:Connect(function()
    if open == true then
        open = false
        ACHIEVEMENTS:TweenPosition(UDim2.new(0.32, 0,0.134, 0), "InOut", "Quad", 0.5, true)
    else
        open = true
        ACHIEVEMENTS:TweenPosition(UDim2.new(0.32, 0,1, 0), "InOut", "Quad", 0.5, true)
    end
end)

@Catasangel_2007 One thing you can try is adding a debounce to allow the tweens to finish playing:

local ACHIEVEMENTS = script.Parent.Parent.Parent.GUI1
--local Cancel = script.Can
local open = true

local debounce = false

script.Parent.MouseButton1Click:Connect(function()
	if debounce then return end
	debounce = true

    if open == true then
        open = false
        ACHIEVEMENTS:TweenPosition(UDim2.new(0.32, 0,0.134, 0), "InOut", "Quad", 0.5, true)
    else
        open = true
        ACHIEVEMENTS:TweenPosition(UDim2.new(0.32, 0,1, 0), "InOut", "Quad", 0.5, true)
    end

	task.wait(0.5)
	debounce = false
end)

@Catasangel_2007 I commented out the script.Can lines since there doesn’t seem to be an Instance named Can that’s a child of the script

1 Like

Almost but some how i can’t use icon


Do i need “If then”?

This should work for both buttons:

local ACHIEVEMENTS = script.Parent.Parent.Parent.GUI1

local open = true

local debounce = false

local function onButtonPress()
	if debounce then return end
	debounce = true

    if open == true then
        open = false
        ACHIEVEMENTS:TweenPosition(UDim2.new(0.32, 0,0.134, 0), "InOut", "Quad", 0.5, true)
    else
        open = true
        ACHIEVEMENTS:TweenPosition(UDim2.new(0.32, 0,1, 0), "InOut", "Quad", 0.5, true)
    end

	task.wait(0.1)
	debounce = false
end

script.Parent.MouseButton1Click:Connect(onButtonPress)
script.Parent.Parent.MouseButton1Click:Connect(onButtonPress)
1 Like

it happen again like need double click
image

I’ll rewrite the code, but just to confirm the script is the LocalScript named Cancel and the button is the image button named CANCELBUTTON, and the Gui you’d like to move is the one named GUI1

1 Like

Yes
image

This code should work in that case:

local cancelButton = script.Parent
local gui1 = cancelButton:FindFirstAncestor("GUI1")

local debounce = false

local open = true

cancelButton.MouseButton1Click:Connect(function()
	if debounce then return end
	debounce = true

	if open then
		gui1:TweenPosition(UDim2.new(0.32, 0,0.134, 0), "InOut", "Quad", 0.5, true)
		open = false
	else
		gui:TweenPosition(UDim2.new(0.32, 0,1, 0), "InOut", "Quad", 0.5, true)
		open = true
	end

	task.wait(0.5)
	debounce = false
end)

Admittedly it’s not that different than the one I already gave you, but hopefully this version works

Tbh The LScript Call “AnotherGUI” that i put on Badg/Achi
image
Full of GUI

Also it not work cause not found GUI1

Replace local gui1 = cancelButton:FindFirstAncestor("GUI1") with local gui1 = cancelButton:FindFirstAncestor("GUI") since the LocalScript is the one named Another GUI

1 Like

it not work at all but atleast is funny cause it move the UI Icon