Toggle gui not working

Hey gamers, I’m trying to create a simple script that opens and closes a gui. I have no clue why this isn’t working. I’ve tried various different solutions I got from the internet, including the devforum, but nothing works.

Explorer:
image

Script

local click = script.Parent.MouseButton1Click
local menu = game.StarterGui.Menu.Frame

local function toggle()

end

click:Connect(function()
	if menu.Visible == true then
		menu.Visible = false
	else
		menu.Visible = true
	end
end)
1 Like
local click = script.Parent
local client = game:GetService("Players").LocalPlayer
local menu = client.PlayerGUI.Menu.Frame

click.Activated:Connect(function()
	menu.Visible = not menu.Visible
end)

You were changing the frame in StarterGUI and not PlayerGUI.
Also, interact with UI objects on the client (LocalScript).

1 Like

three things:

I wouldn’t make a Click variable instead I would do script.Parent.MouseButton1Click:Connect(function()

Also Changing the ui needs to be done in a local script not a server script

Also the menu variable should be getting the player’s playergui instead of startergui.

Your path goes to StarterGui. In the game, StarterGui does not react in any way, this is the same as StarterPack. Change the path from game.StarterGui to game.Players.LocalPlayer.PlayerGui:WaitForChild(“Menu”).Frame.
(also, change Script to LocalScript)

local click = script.Parent.MouseButton1Click
local menu = game.Players.LocalPlayer.PlayerGui:WaitForChild("Menu").Frame

local function toggle()

end

click:Connect(function()
	if menu.Visible == true then
		menu.Visible = false
	else
		menu.Visible = true
	end
end)

Thanks! I was still stuck on this for a while, but this works perfectly once I changed to a local script.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.