Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

A GUI in my game won't open or close? Not sure what to do.

So basically, all the GUIs in my game work except for the Rules GUI This is what i put in the local script

local Frame = script.Parent.Parent.Parent.Parent.Rules.Frame

script.Parent.MouseButton1Click:connect(function()
	if Frame.Visible == false then
		Frame.Visible = true
	elseif
		Frame.Visible == true then
		Frame.Visible = false
	end
end)

Here's a photo of the GUIs itself: https://prnt.sc/jxwa3u

I'm not sure what it is im doing wrong. What should i change to fix this?

3 comments

0

Oh my you have a ton of Parents, but try using just MouseClick instead of MouseButton1Click

0

Why not put the LocalScript under the frame Rules itself?

0

I separated all the GUIs which is why there's a lot of parents in the script. https://prnt.sc/jxwkgd

3 answers

It won’t work since you used connect and it’s Connect.

script.Parent.MouseButton1Click:Connect(function()
    Frame.Visible = not Frame.Visible
end)

Review:

The script changes the current Visible state of the Gui, and sets it to its opposite.

If it is true, set true to false, and vice versa.

This code should work

local Frame = script.Parent.Parent.Parent.Parent.Rules.Frame
local Toggle = false
	 
script.Parent.MouseButton1Click:Connect(function()
	if Toggle == false then
		Frame.Visible = true
		Toggle = true
	else
		Frame.Visible = false
		Toggle = false
	end
end)

Things I found that could have been not working.

  1. When you connect your event to a function you used a lower case c when that is deprecated. From now on use Connect over connect.
  2. I added a simple variable that is set to false. When the player clicks it I check if the variable is false. If so then open the gui and set the variable to true. Else close the gui and set the variable to false.
  3. I changed the elseif statement to just else.

So you know the code above is untested. Hope this works.

1 comment

0

You made your code unnecessarily long. You don’t need an if statement checking the visibility

On your code,

local Frame = script.Parent.Parent.Parent.Parent.Rules.Frame
script.Parent.MouseButton1Click:connect(function()
    if Frame.Visible == false then
        Frame.Visible = true
    elseif -- ?? Nothing ??
        Frame.Visible == true then
        Frame.Visible = false
    end
end)

On the elseif statement you did not state anything and I've noticed that you may have accidently misplaced it. So to fix this, you have to do this instead:

local Frame = script.Parent.Parent.Parent.Parent.Rules.Frame
script.Parent.MouseButton1Click:connect(function()
    if Frame.Visible == false then
        Frame.Visible = true
    elseif Frame.Visible == true then    -- :D
        Frame.Visible = false
    end
end)

1 comment

0

Even as little as misplacing can make your script not work :)

This discussion is preserved as it was. New answers, comments, and votes are closed.