Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to make gui diseapear with click detector?

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago

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)
0
it doesnt work QuestionableScript3r -6 — 4y
0
Where exactly is your screengui? ImNotKevPlayz 4 — 4y
0
in startergui QuestionableScript3r -6 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

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!

Answer this question