Scripting help guis

  1. I want when clicked Frame Frame1 visible = true

  2. **
    https://gyazo.com/c70fa8d74a52b16ad3d5d8e85ddf105c**

  3. I search on developer hub, and youtube I ask roblox discord development too

local Frame = script.Parent:WaitForChild("Frame")

local Frame1 = script.Parent:WaitForChild("Frame1")

Frame.OnMouseClick:Connect(function()
      Frame1.Visible = not Frame1.Visible
end)

1 Like

It just means it can not find frame1. Make sure that it is where you need it to be, and you are using the right path

1 Like


https://gyazo.com/225a53bb8999922d1de5410dcba85fca

Umm where I mistake??

1 Like

This error means the objects you are waiting for will never exist so the yield will wait forever.

You forgot to put another parent in the 3rd line to make the path to Frame1 right. At the moment you are assuming Frame1 is a child of Frame:

local Frame = script.Parent:WaitForChild("Frame")

local Frame1 = script.Parent.Parent:WaitForChild("Frame1") -- I added another parent here to make the path right

Frame.OnMouseClick:Connect(function()
      Frame1.Visible = not Frame1.Visible
end)

I made but same error Interesing…

I am assuming you are getting another initiate yield warning on this line(when I wrote my previous post I forgot to check if this line was causing the warning as well):

If you are getting an infinite yield warning on this line then the reason for this is because you are attempting to use WaitForChild() on the Frame when this is the object that you are waiting for.

Instead you could directly access the the frame by doing script.Parent instead of using WaitForChild() because using WaitForChild is redundant in this case because frame already exists when the script runs:

local Frame = script.Parent -- Removed the WaitForChild on this line

local Frame1 = script.Parent.Parent:WaitForChild("Frame1") -- I added another parent here to make the path right

Frame.OnMouseClick:Connect(function()
      Frame1.Visible = not Frame1.Visible
end)

thank you, but gives this error


https://gyazo.com/53bd4b412fa35ab3d1ad26bc8051edc3

My script you could use (Not tested it please test it)

local frame = script.Parent
local frame2 = script.Parent.Parent:FindFirstChild("Frame2")

local function click()
frame2.Visible = true
end)

frame.MouseButton1Click(function(click)

You are getting this error because this event doesn’t exist for ImageButtons. Instead you could use the MouseButton1Click() event. Please read through the developers hub page about ImageButtons for more information on what types of functions and events are available for ImageButtons: ImageButton | Documentation - Roblox Creator Hub

Thank you, but not working… (I change variable names to correct)

Alright great! So was this the solution to your problem?

I made this
local Frame = script.Parent

local Frame1 = script.Parent.Parent:FindFirstChild("Frame1")

local function click()

Frame1.Visible = true

end)

frame.MouseButton1Click(function(click)


https://gyazo.com/06672ac542bbae24541ea404f2e21f5b

but Gave this error

Alright I’ll go in studio and try to make one for you. (Is it click the button and open gui?)

Yes, click ImageButton to open ImageLabel

The ) is not necessary unless you’re creating an anonymous function. But because you connected the event after creating the function, you eliminated the need for the parentheses.

You’re not connecting the event, thus it is not triggering and will give you an error. Events are basically things that happen only once something is triggered. So once that ‘object’ is triggered, it needs to connect the event with information to do.
According to the output error, you forgot a “)” after this line.

Here’s your code cleaned up.

local Frame = script.Parent
local Frame1 = Frame.Parent:FindFirstChild("Frame1")
local debounce = false

Frame.MouseButton1Click:Connect(function()
	if debounce == false then
		Frame1.Visible = true
		debounce = true
	end
end)
2 Likes

thanks, It worked!
If I want when clicked again close
this code will work?

local Frame = script.Parent

local Frame1 = Frame.Parent:FindFirstChild("Frame1")

local debounce = false

local debounce_1 = true

Frame.MouseButton1Click:Connect(function()

if debounce == false then

Frame1.Visible = true

debounce = true

end

end)

Frame.MouseButton1Click:Connect(function()

if debounce_1 == true then

Frame1.Visible = false

debounce_1 = false

end

end)
1 Like

I’m going to guess that your script will probably freak out, because it doesn’t know which one of the event triggers to choose. Probably will run the first one and completely ignore the 2nd half of the code. So no, don’t do that. Use an elseif statement to catch if the frame is already visible.
Code below:

local Frame = script.Parent
local Frame1 = Frame.Parent:FindFirstChild("Frame1")
local debounce = false

Frame.MouseButton1Click:Connect(function()
	if debounce == false then
		Frame1.Visible = true
		debounce = true
	elseif debounce == true then
		Frame1.Visible = false
		debounce = false
	end
end)
1 Like

Thanks!!! It worked!! (I add Frame = script.Parent to work)

1 Like

Adding a debounce here is fairly pointless and is just bloating the script with unnecessary operations. Instead you should be directly checking the visibility of the frame and change the visible property accordingly. There could be some edge cases where the frame is visible when the debounce value says it isn’t or vice versa. This could be caused when another script changes the visible property of the frame.

See:

local Frame = script.Parent
local Frame1 = Frame.Parent:FindFirstChild("Frame1")

Frame.MouseButton1Click:Connect(function()
	if Frame1.Visible then -- Frame is visible
		Frame1.Visible = false
	else -- Frame is not visible
		Frame1.Visible = true
	end
end)