Open GUI not working after closing

Hi, i have a script that opens a gui after clicking a button (clickdetector btw) and on the gui theres a close button. However, after i closed the gui using the close button i can’t open back when clicking the clickdetector button. Why is this happening?

My clickdetector script

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	player:WaitForChild("PlayerGui").SyufGUI.SyufFrame.Visible = true
end)

My gui close script

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	player.PlayerGui.SyufGUI.SyufFrame.Visible = false
end)

This is how the GUI looks in startergui incase if u guys need it.
image

1 Like

What type is each script (they both need to be the same type)

the clickdetector is a script
the gui close is localscript

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if player.PlayerGui.SyufGUI.SyufFrame.Visible == true then
		player.PlayerGui.SyufGUI.SyufFrame.Visible = false
	end
end)
1 Like

Change both of them to scripts.

1 Like

Doesn’t close after i changed the localscript to script

You should reference the click detector from the same local script that makes the gui close. Everything in the same localscript. Like this:

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	player.PlayerGui.SyufGUI.SyufFrame.Visible = false
end)

workspace.Part.ClickDetector.MouseClick:Connect(function() --Change the path of the click detector to your path.
	player.PlayerGui.SyufGUI.SyufFrame.Visible = false
end)

The problem you had is that you were making the gui visible first on the server, which makes it replicate to the client, but then you were closing it in the client, which does not replicate to the server, so the gui was never closed in the server, and when you tried to open it for the second time it didn’t because it was already opened. Sorry if the explanation is a bit confusing.

4 Likes

Also change game.Players.LocalPlayer to script:FindFirstAncestorOfClass(“Player”)

1 Like

Oh alright ill try that and see if it works

2 Likes

The script works! Thanks DaGpm

1 Like