Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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?

0
Oh my you have a ton of Parents, but try using just MouseClick instead of MouseButton1Click Rallient 40 — 5y
0
Why not put the LocalScript under the frame Rules itself? Rallient 40 — 5y
0
I separated all the GUIs which is why there's a lot of parents in the script. https://prnt.sc/jxwkgd deacent 5 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago

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.

Ad
Log in to vote
0
Answered by
zblox164 531 Moderation Voter
5 years ago

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.

0
You made your code unnecessarily long. You don’t need an if statement checking the visibility User#19524 175 — 5y
Log in to vote
0
Answered by
Nep_Ryker 131
5 years ago
Edited 5 years ago

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)
0
Even as little as misplacing can make your script not work :) Nep_Ryker 131 — 5y

Answer this question