Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Open / Close Gui Dosent know why i cant use this?

I dont really know why this isnt working why cant i do like this when i clicked on the textbutton then i close the gui but it dosent seem to work. Heres the code

function onClick()
	game.StarterGui.ChooseLevel.Main.Visible = false
end

script.Parent.MouseButton1Click:connect(onClick)

2 answers

Try making a local script inside the text button and then paste the following code in it:

script.Parent.MouseButton1Click:connect(function()
	local GUI = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ChooseLevel"):WaitForChild("Main")

	if GUI .Visible then
		GUI.Visible = false
		script.Parent.Text = "Open"
	else
		GUI.Visible = true
		script.Parent.Text = "Close"
	end
end)

I even added some extra code so it changes the button text to say "Open" or "Close"!

You are supposed to find the GUI in the playerGui, not the StarterGui: Game.Players.LocalPlayer.PlayerGui.ChooseLevel.Main.Visible . I believe you are setting the Gui to not show up when new players join the game.

8 comments

0

It gives me this error "Localplayer is not a valid member of DataModel" and i want the gui to show up when a new player joins i dont want it to be like open first i want it to be like if i join the server then the gui is there on the start

0

Wait, i should've asked this first before posting my answer... Where do you have the script? Is it a Local script?

0

its in a textbutton, and no its not a local script

0

Is the textbutton on a brick? Or on the players screen?

0

on the players screen

0

Just a heads up. It's "game.Players.LocalPlayer". Not "game.LocalPlayer"

0

Oh that's right! Thanks @TheHospitalDev. I just edited my post.

0

Another question, where do you have the textbutton along with the script? Inside Workspace or inside the StarterGUI? If you could provide a picture with how you have it set-up then it would be much easier to help you. This is only if you are absolutely sure you want to have it this way. Otherwise, read ScripterTonys answer up above. Do what he says, and then put the textbutton along with the scrip

This discussion is preserved as it was. New answers, comments, and votes are closed.