When the player joins and clicks the text button "play", this script should make the "title screen" screen gui disappear

Hello fellas.

Trying to make this local script that is the child of the screen gui “Title Screen” close itself when the player clicks the text button “Play Button”. It is not working.

local TitleScreen = script.Parent
local PlayButton = script.Parent["Play Button"]

PlayButton.MouseButton1Click:Connect(function()
	script.Parent.TitleScreen.Visible = not TitleScreen.Visible
end)

What am I doing wrong?

2 Likes

You could have just done: script.Parent.TitleScreen.Visible = false

change ‘not TitleScreen.Visible’ to false and it should work

Try doing TItleScreen:WaitForChild(“Play Button”) as well in your PlayButton line.

1 Like

didn’t work for some reason.

local TitleScreen = script.Parent
local PlayButton = script.Parent["Play Button"]

PlayButton.MouseButton1Click:Connect(function()
	script.Parent.TitleScreen.Visible = false
end)

Like I said, :WaitForChild() on PlayButton and no need to do script.Parent.TitleScreen.Visible it’s just as easy to do TitleScreen.Visible. That’s why you declared the variable is it not?

what you did should work, make sure you are indexing the correct instance, make sure PlayButton is a child of script.Parent, add a WaitForChild in case it didn’t load,

PlayButton = script.Parent:WaitForChild(“Play Button”)

tell us if there are errors in the output.

1 Like

Like this?

local TitleScreen = script.Parent
local PlayButton = script.Parent["Play Button"]

PlayButton.MouseButton1Click:Connect(function()
    TitleScreen:WaitForChild("Play Button")
	script.Parent.TitleScreen.Visible = not TitleScreen.Visible
end)

No.

local PlayButton = TitleScreen:WaitForChild("Play Button")

^ Should resolve your issue. Also open up output if you don’t already cause I guarantee there’s a error there.

local TitleScreen = script.Parent
local PlayButton = TitleScreen:WaitForChild("Play Button")

PlayButton.MouseButton1Click:Connect(function()
	TitleScreen.Visible = false
end)

Try it for yourself in studio.

“visible is not a valid member of screengui”
@greatneil80

then there you have it. Do

TitleScreen.Enabled

1 Like

.Enabled, not Visible, Enabled is for screen gui’s

1 Like

@greatneil80 thank you very much.

1 Like