Help with script detector showing GUI Frame

Hello! So I am trying to script an arcade game and am having a hard time with this script:
I want it when the player clicks the button, this frame appears visible but it isn’t working.

click.MouseClick:connect(function(player)
     local gui = game.StarterGui.ScreenGui.Frame
	 gui.Visible = true
	if true then
		print("Visible!")
	else
		print("Not Visible!")
	end
end)

I added a conditional statement and the output says visible, but it isn’t working. Anyone got any ideas?

1 Like

try if gui.Visible == true then

1 Like

You’ll have to reference the PlayerGui, instead.

click.MouseClick:connect(function(player)
     local gui = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").Frame
	 gui.Visible = true
	if gui.Visible == true then
		print("Visible!")
	else
		print("Not Visible!")
	end
end)
1 Like

Hi jumbopushpop112!

It looks like you’re setting the frame inside of the StarterGui to visible. If you want the player’s frame to become visible you can try finding the frame through the player’s PlayerGui. An example is below!

click.MouseClick:connect(function(player)

     local gui = player.PlayerGui.ScreenGui.Frame -- Changed this!

	 gui.Visible = true
	if true then
		print("Visible!")
	else
		print("Not Visible!")
	end
end)
1 Like

Or you can do
local gui = script.Parent.ScreenGui.Frame
if its not working add more Parents like
script.Parent.Parent.ScreenGui.Frame

I have my GUI in Starter Gui, doesn’t work yet. Do I need to fix something?

You do need to fix something. You need to update the PlayerGui instead of the Starter Gui. Code examples above or just use this:

click.MouseClick:connect(function(player)
     local gui = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").Frame
	 gui.Visible = true
	if gui.Visible == true then
		print("Visible!")
	else
		print("Not Visible!")
	end
end)

Why is this?

Well, StarterGui holds GUI objects and LocalScripts. Children of this object are copied into the player’s PlayerGui when they spawn.

PlayerGuis hold the GUI objects that will be displayed to the player. If ScreenGui is a child of a PlayerGui, then any object inside of the ScreenGui will be drawn to the player’s screen. Any LocalScript will run as soon as it is inserted into a PlayerGui. Meaning, if the script isn’t in the UI itself, then the UI must be edited using the PlayerGui.

Also made a slight edit to your code.

1 Like

Hey man! Thanks a lot. It finally works now, thanks for the help. It means a lot to me. I found an answer that works thanks to you. Fast and easy explanation. :smiley:

1 Like