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