Frame in ScreenGUI won't disappear

Hi developers:

So I’m having trouble with my code that makes a Frame disappear when a TextButton is clicked. At the start of the game, it’s invisible. When a player clicks on the button that “starts” the game, the Frame reappears. However, when I click the TextButton within that Frame, the following code (located in the TextButton) won’t work to make the Frame disappear when the TextButton is clicked:

script.Parent.MouseButton1Down:Connect(function()
	script.Parent.Parent.Visible = false -- Makes the frame disappear
end)

That was the code that isn’t working. The full code in the script is:

script.Parent.MouseButton1Down:Connect(function()
	script.Parent.Parent.Visible = false -- Makes the frame disappear
end)		

-- This next part is just assigning a billboard GUI to the player's head when the button is clicked

local gamedesignertitle = game.ServerStorage.GameDesigner -- This is the billboard GUI 

script.Parent.MouseButton1Down:Connect(function()
	gamedesignertitle:Clone().Parent = script:FindFirstAncestorOfClass("Player").Character.Head
end)

I have 11 TextButtons within the Frame with a similar purpose. Each is supposed to, when clicked, assign a specific billboard GUI to the player’s head and close the Frame (make it invisible).

Any ideas as to what is wrong? (The code is located in a server script and not a LocalScript because I needed to access ServerStorage for the Billboard GUIs)

1 Like

Try using a localscript and instead placing the billboard GUIs in ReplicatedStorage

2 Likes

Hi,I’d suggest using a local script,you can have a server script on “ServerScriptService” and a remote on replicated storage and when you need to clone the billboard gui just fire the remote,the first argument will be the player.

1 Like

Thank you! I changed my script into a LocalScript, put the billboard GUIs in ReplicatedStorage, and now my code says this:

script.Parent.MouseButton1Down:Connect(function()
	script.Parent.Parent.Visible = false
end)

local buildertitle = game.ReplicatedStorage.Builder -- This is the billboard GUI 

script.Parent.MouseButton1Down:Connect(function()
	buildertitle:Clone().Parent = script:FindFirstAncestorOfClass("Player").Character.Head
end)

And it worked! Thanks again!

I suppose your method would be an alternative way to do this. Thanks for your input!

1 Like