Why is my UI Button not opening my Frame?

Hello.

I recently attempted to create my own UI, since I am relatively new to scripting on Roblox Studio. I needed to create a frame, and for some reason, the way I always did, and saw from tutorials, didn’t work. I thought that it was a waste of time to go back to watching tutorials, so Instead, I decided to ask the rest of the community.

Here’s the code:

local Button = script.Parent
local Frame = Button.Parent.Frame

Button.MouseButton1Click:Connect(function()
Frame.Visible = true
if Frame.Visible == true then
    Frame.Visible = false
    end)
end)

It would be much appreciated if someone could find the reason for why this isn’t working. Like I said, I’m very new to coding, so please take it easy on me.

1 Like

Make sure your ‘Frame’ visible property is set to false in Roblox Studio then in the LocalScript try this:

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

Button.MouseButton1Click:Connect(function()
    Frame.Visible = true
else
    Frame.Visible = false
end)
3 Likes

Thank You for replying so quickly, and I will definitely give this a try.

Once again, Thank You for your time.

2 Likes

Apparently putting, “else” Inside of MouseButton1Click function, isn’t actually possible.

Thank You for trying to help me though.

1 Like

Ah I think I have a simple fix for this:

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

Button.MouseButton1Click:Connect(function()
    Frame.Visible = not Frame.Visible
end)
1 Like