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
8 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.

local gui = script.Parent
gui.Mouse1Click:connect(function(click)
    if gui then
        gui.Visible = false
        local value = gui.Value
        if value == false then
            value == true
            if value == true then
                gui.Visible = false
            end
        end
    end
end)

2 answers

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

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

gui = script.Parent --Shortcuts because newer scripters are lazy and like doing this for some reason.

gui.MouseButton1Click:connect(function() --On click
    if gui.Visible == true then gui.Visible = false else return end --Make invisible or return (The return should never happen)
end)

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

gui = script.Parent --Shortcut
guisToHide = {gui1,gui2} --An array (Or as know on ROBLOX, a table) of guis that will also become invisible

gui.MouseButton1Click:connect(function() --This is how we call a click function
    if gui.Visible == true then --If it's visible
        gui.Visible = false  --Make it invisible
        for _,c in pairs(guisToHide) do --A for loop that goes through the array
            c.Visible = false --Make the guis invisible
        end
    end
end)

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

gui = script.Parent 
guisToHide = {gui1,gui2}

if not game.Players.LocalPlayer:FindFirstChild("Boolean") then --If the value doesn't exist
    local bool = Instance.new("BoolValue",game.Players.LocalPlayer) --Create the value
    bool.Name = "Boolean" --Name it
else --If it exists
    gui.Visible = false --Make the guis invisible
    for _,c in pairs(guisToHide) do
        c.Visible = false
    end
end

gui.MouseButton1Click:connect(function() 
    if gui.Visible == true then
        gui.Visible = false
        for _,c in pairs(guisToHide) do
            c.Visible = false
        end
    end
end)

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

gui = script.Parent

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

GuiButton.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 — 8y
0
Obviously? Making it local is pointless, which is why I removed it. Learn to read. drahsid5 250 — 8y
Ad
Log in to vote
-2
Answered by
Legojoker 345 Moderation Voter
8 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

local 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

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

local value = gui.Value.Value -- Change the name
if value == false then
        value = true
        if value == true then
              gui.Visible = false
       end
end

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 — 8y
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 — 8y

Answer this question