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.
01 | local gui = script.Parent |
02 | gui.Mouse 1 Click: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 |
13 | end ) |
You're doing too much, if you want the GUI to become invisible do this:
1 | gui = script.Parent --Shortcuts because newer scripters are lazy and like doing this for some reason. |
2 |
3 | gui.MouseButton 1 Click: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) |
5 | end ) |
if you want to hide a set of GUIs you can do something like this:
01 | gui = script.Parent --Shortcut |
02 | guisToHide = { gui 1 ,gui 2 } --An array (Or as know on ROBLOX, a table) of guis that will also become invisible |
03 |
04 | gui.MouseButton 1 Click: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 |
11 | end ) |
And since you also want to to only appear once, you could try:
01 | gui = script.Parent |
02 | guisToHide = { gui 1 ,gui 2 } |
03 |
04 | if 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 |
07 | else --If it exists |
08 | gui.Visible = false --Make the guis invisible |
09 | for _,c in pairs (guisToHide) do |
10 | c.Visible = false |
11 | end |
12 | end |
13 |
14 | gui.MouseButton 1 Click:connect( function () |
15 | if gui.Visible = = true then |
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
1 | gui = script.Parent |
On line two you call a method that doesn't exist. Mouse1Click is not a valid member of the GuiButton array.
1 | GuiButton.MouseButton 1 Click(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.
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
1 | 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
1 | 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):
1 | local value = gui.Value.Value -- Change the name |
2 | if value = = false then |
3 | value = true |
4 | if value = = true then |
5 | gui.Visible = false |
6 | end |
7 | 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.