✓ Accepted answer
A ClickDetector is an Object designed to integrate cursor related features into a BasePart, and a BasePart only.
There are already existing RBXScriptSignals designed specifically for GUIButton click-events, and these are to be only used for it's base-class too. The signal you are looking for is .MouseButton1Click.
There is one final issue with your code, you're referencing the wrong UI. StarterGui is merely a background replication container meant to transfer the UI descendants into each unique user. The authentic User Interface that correlates to GUIs on-screen are located under a local folder within the Player, called PlayerGui. To make live adjustments, you must reference this folder instead:
local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local ScreenGui = PlayerGui:WaitForChild("ScreenGui")
local Button = script.Parent
local function SetInvisible()
for _,Gui in pairs(ScreenGui:GetChildren()) do
if (Gui:IsA("GuiObject")) then
Gui.Visible = false
end
end
end
Button.MouseButton1Click:Connect(SetInvisible)
1 comment
The "if (Gui:IsA("GuiObject")) then" Says the "If" is wrong, could that mean that i put it in the wrong script?