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

Can you guys help me Im trying to to make it so that the gui only appears once. Whats wrong?

Asked by
duckyo01 120
9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I'm trying to make it so that this gui only shows up once and when the button called close is clicked it makes the gui not visible. And the bool value starts false and when it turns true it should not show my gui after I die.

01local gui = script.Parent
02gui.Mouse1Click:connect(function(click)
03    if gui then
04        gui.Visible = false
05        local value = gui.Value
06        if value == false then
07            value == true
08            if value == true then
09                gui.Visible = false
10            end
11        end
12    end
13end)

2 answers

Log in to vote
2
Answered by
drahsid5 250 Moderation Voter
9 years ago

You're doing too much, if you want the GUI to become invisible do this:

1gui = script.Parent --Shortcuts because newer scripters are lazy and like doing this for some reason.
2 
3gui.MouseButton1Click:connect(function() --On click
4    if gui.Visible == true then gui.Visible = false else return end --Make invisible or return (The return should never happen)
5end)

if you want to hide a set of GUIs you can do something like this:

01gui = script.Parent --Shortcut
02guisToHide = {gui1,gui2} --An array (Or as know on ROBLOX, a table) of guis that will also become invisible
03 
04gui.MouseButton1Click:connect(function() --This is how we call a click function
05    if gui.Visible == true then --If it's visible
06        gui.Visible = false  --Make it invisible
07        for _,c in pairs(guisToHide) do --A for loop that goes through the array
08            c.Visible = false --Make the guis invisible
09        end
10    end
11end)

And since you also want to to only appear once, you could try:

01gui = script.Parent
02guisToHide = {gui1,gui2}
03 
04if not game.Players.LocalPlayer:FindFirstChild("Boolean") then --If the value doesn't exist
05    local bool = Instance.new("BoolValue",game.Players.LocalPlayer) --Create the value
06    bool.Name = "Boolean" --Name it
07else --If it exists
08    gui.Visible = false --Make the guis invisible
09    for _,c in pairs(guisToHide) do
10        c.Visible = false
11    end
12end
13 
14gui.MouseButton1Click:connect(function()
15    if gui.Visible == true then
View all 21 lines...

Reference: GUIButton Button1Click Tables For loop

So, what did you do wrong? Well, On line one you made gui local. It's not in a function, every part of the code will be able to reference it, it should be public. So you'd take the local away and make it

1gui = script.Parent

On line two you call a method that doesn't exist. Mouse1Click is not a valid member of the GuiButton array.

1GuiButton.MouseButton1Click(connect(function()

is what you meant.

on line 5 you made and attempt to reference a nil value. (It doesn't exist)

I fixed that by creating a value that is referenced. (I also made it to where it can only work once for you)

The rest is an attempt to make the gui invisible if it's clicked and already supposed to be invisible. I fixed that by checking for the value that you used for the only once thing.

0
Making gui local doesn't keep it from being used in the rest of the script if it isn't inside of anything. Legojoker 345 — 9y
0
Obviously? Making it local is pointless, which is why I removed it. Learn to read. drahsid5 250 — 9y
Ad
Log in to vote
-2
Answered by
Legojoker 345 Moderation Voter
9 years ago

gui needs to be a button (I'm assuming it is), and line two of your code should be

gui.MouseButton1Click:connect(function()

click isn't necessary. You can never be too safe, but if they just clicked the gui, you can probably assume it still exists. I have no idea what gui.Value is, if it's a userdata boolean value object NAMED Value, then you might want to change it to something different. Also, because it's a userdata value, to get its actual value you will need to access that specific property. For example, if I want to make variable cat equal my boolean value Cat in workspace, I would say

1local cat = game.Workspace.Cat.Value

HOWEVER, this means that the variable cat is NOT connected to the userdata; I can't call cat and change the value of its userdata. If you want to change it again, like you say on line 7, make it set to

1local cat = game.Workspace.Cat

and then to access the value say cat.Value. In the end I think you want your code to look like this (lines 5 to 11):

1local value = gui.Value.Value -- Change the name
2if value == false then
3        value = true
4        if value == true then
5              gui.Visible = false
6       end
7end

another thing to keep in mind is double equal signs are checking whether they are equal, not setting a variable, which you attempt at line 7. It is fixed above.

I'm not really sure what you're attempting here though, because the if statements are compounded inside each other. Some parts just seem unnecessary.

0
A value to control a client based object should not be in a parent controlled by the server. drahsid5 250 — 9y
0
...That was just an example. I wasn't ACTUALLY doing that for the client. I'm explaining to him how values work. Legojoker 345 — 9y

Answer this question