Gui Won't Show When Part Is Clicked

Hello Guys Now I Work On Something. But there Is A Problem In The Script i Want To Make When Part Is Clicked By Click Detector The Gui Is Showing Up.
Here’s The Code :

script.Parent.Parent.ClickDetector.MouseClick:Connect(function()
	if game.StarterGui.ScreenGui.Frame.Visible = false then
		game.StarterGui.ScreenGui.Frame.Visible = true
	else
		print("There Is An Error In This Script")
	end
end)

this is the output :

Thx For Reading :slight_smile:

2 Likes

you forgot to add “==” at the if statement
and also using game.StarterGui wont work instead u should do this

script.Parent.Parent.ClickDetector.MouseClick:Connect(function(plr)
	if plr.PlayerGui.ScreenGui.Frame.Visible == false then
		plr.PlayerGui.ScreenGui.Frame.Visible = true
	else
		print("There Is An Error In This Script")
	end
end)
1 Like

Many things wrong with your script.

  1. What MrchipsMa said
  2. I assume this script is a Server-sided script (meaning NOT a local script). You cannot change the visibility of the frame via a server sided script.
  3. Use a remote event and do :FireAllClients() , and then in the local script do something like this. Do :FireClient() if you only want the visibility to be changed for the player who clicked the part.

Read this article to learn more about remote events (they are very useful)

re.OnClientEvent:Connect(function()
    if game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible == false then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true
	else
		print("There Is An Error In This Script")
	end
end)
1 Like

You actually made two mistakes or more and the first one is you forgot to add the == ( what MrchipsMa said) on the line “if game.StarterGui.ScreenGui.Frame.Visible = false then” and the other one is you actually need to change this to a Localscript so you can access the LocalPlayer and change it from the Player’s GUI (changing properties won’t work in a server-script sided script and on the “StarterGui”) So here is what you need to do to run your script!

script.Parent.Parent.ClickDetector.MouseClick:Connect(function()
	if game.StarterGui.ScreenGui.Frame.Visible == false then
		game.Players.LocalPlayer.PlayerGUI.ScreenGui.Frame.Visible = true
	else
		print("There Is An Error In This Script")
	end
end)

(Only switch the one that you are going to set it’s visibility to true the first one) the one that you told the script that If the frame isn’t visible then make it visible doesn’t need to be changed aka this line)
if game.StarterGui.ScreenGui.Frame.Visible == false then

1 Like
local model = script.Parent.Parent
local click = model.ClickDetector

click.MouseClick:Connect(function(player)
	player.PlayerGui.ScreenGui.Frame.Visible = not player.PlayerGui.ScreenGui.Frame.Visible
end)

Here’s the simplest solution.

1 Like

Thanks for all Of Your feedback! I appriciated it