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

how to make gui diseapear with click detector?

im trying to make a gui disapear when you click a GUI BUTTON

here is the code

script.Parent.ClickDetector.RightMouseClick:Connect(function()
	script.Parent.Parent.Parent.ScreenGui:Destroy()
end)

2 answers

First of all, please don't use :Destroy() function unless you don't need that object anymore. You can use the property Visible of a GuiObject to determine if it is visible or not without destroying the object. If it is a ScreenGui, you can use the property Enabled instead. With that said, I will explain how you can simply do this.

script.Parent.ClickDetector.RightMouseClick:Connect(function(Player) --Player is the player who clicked the clickdetector
	local PlayerGui = Player:WaitForChild("PlayerGui") --waits for the playergui, inside of the player. the screengui is cloned inside of every player named "PlayerGui."
	local ScreenGui = PlayerGui:WaitForChild("ScreenGui") --the screengui is inside of the playergui
	ScreenGui.Enabled = false --turning enabled to false makes all the GuiObjects inside of the ScreenGui disappear. 
end)

3 comments

0

it doesnt work

0

Where exactly is your screengui?

0

in startergui

Looks like you're a beginner, worry not!

You are not meant to place a ClickDetector in a TextButton, ClickDetectors are for parts in Workspace. I am pretty sure you wanted to not delete a ScreenGui fully, but to make it disappear. Here is your code, but fixed:

script.Parent.ClickDetector.MouseButton2Click:Connect(function() 
	script.Parent.Parent.Parent.ScreenGui.Enabled = false --You can always script a part to toggle the Enabled property on :)
end)

Enjoy!

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