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

Why isn't the clickdetector work for the GUI's?

I'm doing clickdetector and when it clicked the 3 GUI'S would disappear, but the game says the script is fine, even when I clicked the "Start" GUI it doesn't turn the GUI'S transparent.

local clickdetector = script.Parent:WaitForChild("ClickDetector")

clickdetector.MouseClick:Connect(function()
	game.StarterGui.ScreenGui.ImageLabel.ImageTransparency = 1
	game.StarterGui.ScreenGui.ImageLabel.BackgroundTransparency = 1
	game.StarterGui.ScreenGui.TextLabel.TextTransparency = 1
	game.StarterGui.ScreenGui.TextButton.TextTransparency = 1
	
end)

3 answers

✓ 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()
    --[[ Iterates through all Instance within our ScreenGui
    to apply visibility modification
    ]]
    for _,Gui in pairs(ScreenGui:GetChildren()) do
        if (Gui:IsA("GuiObject")) then
            Gui.Visible = false --// Simplifies setting transparency
        end
    end
end

Button.MouseButton1Click:Connect(SetInvisible)

1 comment

0

The "if (Gui:IsA("GuiObject")) then" Says the "If" is wrong, could that mean that i put it in the wrong script?

You don't use clickdetector for guis, you use textbutton or imagebutton. To script, you would do this:

script.Parent.MouseButton1Click:Connect(function()
     script.Parent.ImageLabel.ImageTransparency = 1
     script.Parent.ImageLabel.BackgroundTransparency = 1     
     script.Parent.ScreenGui.TextLabel.TextTransparency = 1	  
     script.Parent.TextButton.TextTransparency = 1
end)

For your information, I scripted this assuming that your heirarchy is startergui -> ScreenGui -> Text/ImageButton -> script

3 comments

1

It's actually better using local scripts on guis

0

It says ImageLabel is not a valid member of TextButton.

0

Oh, I accidentally forgot to add another parent. It should say script.Parent.Parent, not script.Parent

Well, I used this code in my game, and it works just fine. Try this.

-- edit this line to wherever the gui is
script.Parent.Activated:Connect(function()
-- edit this line to wherever the gui is
	    game.StarterGui.ScreenGui.ImageLabel.ImageTransparency = 1
	    game.StarterGui.ScreenGui.ImageLabel.BackgroundTransparency = 1
	    game.StarterGui.ScreenGui.TextLabel.TextTransparency = 1
	    game.StarterGui.ScreenGui.TextButton.TextTransparency = 1
	 
	end)

Just so you know, this script is only possible if the thing you wanna click is a TextButton.

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