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

How do i fix this Open and close GUI script?

Asked by 5 years ago
Edited 5 years ago

So I have an open and close script for one button, but it seems to not work what did I do wrong, and don't say why don't you put a close button on the Frame? Its because the frame does not have enough room.

1script.Parent.MouseButton1Click:Connect(function()
2game.Players.LocalPlayer.PlayerGui.Catalog.Morphs.Visible == true then
3    game.Players.LocalPlayer.PlayerGUI.Catalog.Morphs.Visible = false
4elseif game.Player.LocalPlayer.PlayerGUI.Catalog.Morphs.Visible == false then
5    game.Player.LocalPlayer.PlayerGUI.Catalog.Morphs.Visible = true
6    end
7end)
0
This in a localscript? LennyPlayzYT 269 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

well, you could write the code in fewer lines. liek this:

1local morphs = game.Players.LocalPlayer.PlayerGui.Catalog.Morphs
2script.Parent.MouseButton1Click:Connect(function()
3    morphs.Visible = not Visible
4end)

btw, there must be some other parts in ur code thats making it not work..

one of which could be that an error is taking place, because u forgot the if keyword or game.Players.LocalPlayer.PlayerGui.Catalog.Morphs is not a true directory, and etc

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Well you did one simple mistake. Here's the corrected form:

1script.Parent.MouseButton1Click:Connect(function()
2    if game.Players.LocalPlayer.PlayerGui.Catalog.Morphs.Visible == true then
3        game.Players.LocalPlayer.PlayerGUI.Catalog.Morphs.Visible = false
4    elseif game.Player.LocalPlayer.PlayerGUI.Catalog.Morphs.Visible == false then
5        game.Player.LocalPlayer.PlayerGUI.Catalog.Morphs.Visible = true
6    end
7end)

Basically you just missed putting an "if" before the first statement. Here's a shortened version of your code if you'd like to use that:

1local Catalog = game.Players.LocalPlayer.PlayerGui.Catalog
2 
3script.Parent.MouseButton1Click:Connect(function()
4    if Catalog.Morphs.Visible == true then
5        Catalog.Morphs.Visible = false
6    elseif MorphCLog.Visible == false then
7        Catalog.Morphs.Visible = true
8    end
9end)

In the shortened version, a variable was added for your morph catalog and when you use it, you can use the variable instead of the long version.

Hope this fixed your problem. :)

Edit: Sorry if it might not be indented perfectly. Just re-indent (recommended) them correctly or un-indent them.

Answer this question