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)
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 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)
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
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)
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)
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)
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)