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)
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)
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!