script which doesn’t show errors.
where the script is.
script which doesn’t show errors.
where the script is.
Remove the if
at the front of the connection, you only need open.MouseButton1Click:Connect(function()
.
You should also use a local script instead of a server script.
try switching to a local script
edit: also great panda is right remove the first if behind the function
You can just simply do:
local set = script.Parent
local open = set.Frame.verified_user
local opened = set.Main
open.MouseButton1Click:Connect(function()
opened.Visible = not opened.Visible
end)
You can not use if statement for connections.
Additionally, you referred to the object in the StarterGui, not the PlayerGui. What this does is if your ScreenGui’s ResetOnSpawn
property is checked, only then upon player reset, the changes will be shown.
Quick note: :connect()
is deprecated, use :Connect()
instead.
The elseif statements as we say should not be here. Replace it with else.
A few things that I see that could be causing it
open.MouseButton1Click
event, it’s an event, not a function, as @GreatPanda3 mentionedopened.Visible = not opened.Visible
. To explain what that does, it inverts the boolean (true/false), if say opened is not visible, this code will make it visible, and if it is visible, make it invisible. And typically yes Connect
is used nowadays than connect
That should be all the things I see that need to be changed from what you have shown us which is why I didn’t really state my own thoughts.
Although in the future when you’re ever going to work with boolean checking, there’s something that, although not required, can be used when working with checking a single boolean
Say you have
local a = false
if a == false then
--Code
end
Another way to write this is
```lua
local a = false
if not a then -- If a is false
--Code
end
Like also shown, not
can also act as an inverter for booleans. You can also do this for checking if a value is true
```lua
local a = true
if a then --If a is true
--Code
else --If a was not true, then run this since if a wasn't true, then it's false. Anotehr thing that can be done when working with single boolean checks
--Code
end
When a player joins, everything in StarterGui is cloned into a player’s PlayerGui, so you want to change the PlayerGui not the StarterGui.
Local Script inside of the ScreenGui
local player = game.Players.LocalPlayer
local set = player.PlayerGui.OpenB
local open = set.Frame.verified_user
local opened = set.Main
open.MouseButton1Click:Connect(function()
opened.Visible = not opened.Visible
end)
Server scripts don’t run in StarterGUI (i think)
Scripts inside of UI objects work just like LocalScripts, as far as I’ve noticed. Correct me if I’m wrong here.
However, I prefer LocalScripts over Script just because UI objects are local.
--local Instances
Local Gui = script.Parent.Parent.Parent
--Script
script.Parent.MouseButton1Click:connect(function()
If Gui.Main.Visible == true then --Checks if gui is visible, and "closes it, if visible"/closes Frame
Gui.Main.Visible = false
elseif Gui.Main.Visible == false then --Checks if gui is visible, and "opens it, if invisible"/opens Frame
Gui.Main.Visible = true
end
end)