Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i fix this Open and close GUI script?

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.

script.Parent.MouseButton1Click:Connect(function()
game.Players.LocalPlayer.PlayerGui.Catalog.Morphs.Visible == true then
	game.Players.LocalPlayer.PlayerGUI.Catalog.Morphs.Visible = false
elseif game.Player.LocalPlayer.PlayerGUI.Catalog.Morphs.Visible == false then
	game.Player.LocalPlayer.PlayerGUI.Catalog.Morphs.Visible = true
	end
end)

1 comment

0

This in a localscript?

2 answers

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

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

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

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

script.Parent.MouseButton1Click:Connect(function()
	if game.Players.LocalPlayer.PlayerGui.Catalog.Morphs.Visible == true then
		game.Players.LocalPlayer.PlayerGUI.Catalog.Morphs.Visible = false
	elseif game.Player.LocalPlayer.PlayerGUI.Catalog.Morphs.Visible == false then
		game.Player.LocalPlayer.PlayerGUI.Catalog.Morphs.Visible = true
	end
end)

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:

local Catalog = game.Players.LocalPlayer.PlayerGui.Catalog

script.Parent.MouseButton1Click:Connect(function()
	if Catalog.Morphs.Visible == true then
		Catalog.Morphs.Visible = false
	elseif MorphCLog.Visible == false then
		Catalog.Morphs.Visible = true
	end
end)

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.