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

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

Asked by 5 years ago

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.

1local clickdetector = script.Parent:WaitForChild("ClickDetector")
2 
3clickdetector.MouseClick:Connect(function()
4    game.StarterGui.ScreenGui.ImageLabel.ImageTransparency = 1
5    game.StarterGui.ScreenGui.ImageLabel.BackgroundTransparency = 1
6    game.StarterGui.ScreenGui.TextLabel.TextTransparency = 1
7    game.StarterGui.ScreenGui.TextButton.TextTransparency = 1
8 
9end)

3 answers

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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:

01local Player = game:GetService("Players").LocalPlayer
02 
03local PlayerGui = Player:WaitForChild("PlayerGui")
04local ScreenGui = PlayerGui:WaitForChild("ScreenGui")
05 
06local Button = script.Parent
07 
08local function SetInvisible()
09    --[[ Iterates through all Instance within our ScreenGui
10    to apply visibility modification
11    ]]
12    for _,Gui in pairs(ScreenGui:GetChildren()) do
13        if (Gui:IsA("GuiObject")) then
14            Gui.Visible = false --// Simplifies setting transparency
15        end
16    end
17end
18 
19Button.MouseButton1Click:Connect(SetInvisible)
0
The "if (Gui:IsA("GuiObject")) then" Says the "If" is wrong, could that mean that i put it in the wrong script? kingseller 17 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

1script.Parent.MouseButton1Click:Connect(function()
2     script.Parent.ImageLabel.ImageTransparency = 1
3     script.Parent.ImageLabel.BackgroundTransparency = 1    
4     script.Parent.ScreenGui.TextLabel.TextTransparency = 1  
5     script.Parent.TextButton.TextTransparency = 1
6end)

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

1
It's actually better using local scripts on guis Leamir 3138 — 5y
0
It says ImageLabel is not a valid member of TextButton. kingseller 17 — 5y
0
Oh, I accidentally forgot to add another parent. It should say script.Parent.Parent, not script.Parent IAmNotTheReal_MePipe 418 — 5y
Log in to vote
0
Answered by
Aztralzz 169
5 years ago

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

1-- edit this line to wherever the gui is
2script.Parent.Activated:Connect(function()
3-- edit this line to wherever the gui is
4        game.StarterGui.ScreenGui.ImageLabel.ImageTransparency = 1
5        game.StarterGui.ScreenGui.ImageLabel.BackgroundTransparency = 1
6        game.StarterGui.ScreenGui.TextLabel.TextTransparency = 1
7        game.StarterGui.ScreenGui.TextButton.TextTransparency = 1
8 
9    end)

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

Answer this question