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

I made a script that when clicked,the text disappears in the GUI.But it didn't work.Help how to fix? [closed]

Asked by
svjatik4 -13
3 years ago

I wanted to make a script that when a button is clicked in the GUI, the Text on the GUI screen disappears. But the script didn't work. Here is the script

local textButton = script.Parent

local function Test()
game.StarterGui.ScreenGui.TextLabel.TextTransparency = 1
end

game.Workspace.block.SurfaceGui.TextButton.MouseButton1Click:Connect(Test)

Can you tell me how to fix it?

0
When the game starts, all the GUI gets copied from the StarerGui into PlayerGui, so you'd have to do game.Players.LocalPlayer.PlayerGui instead of game.StarterGui! Befogs 113 — 3y

Closed as Not Constructive by JesseSong

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
0
Answered by
R_alatch 394 Moderation Voter
3 years ago
Edited 3 years ago

Your issue here is that you need to change that specific player's Gui. The components of StarterGui get copied and sent to the player's PlayerGui, so changing the Gui in StarterGui won't do anything.

You should also be using a LocalScript so you can access LocalPlayer.

local textButton = script.Parent

local player = game:GetService("Players").LocalPlayer --define player

local function Test()
    player.PlayerGui.ScreenGui.TextLabel.TextTransparency = 1 --look inside their PlayerGui
end

textButton.MouseButton1Click:Connect(Test) --im assuming you can just do textButton since its defined at the top?
Ad
Log in to vote
0
Answered by
Nckripted 580 Moderation Voter
3 years ago

Hold on. Why are looking in StarterGui for this GUI. This would also explain the issue if you are using a server script (Script) instead of a LocalScript.

StarterGui is just the GUI that gets imported into the Player once the game has initialized. Instead, you might want to look inside PlayerGui. So in a local script inside the TextButton, put the following inside your script.

--Get the Players service
local Players = game:GetService("Players")
`
--Define the player and the TextButton
local player = Players.LocalPlayer
local textButton = script.Parent

--Function Test
local function Test()
    --Now change the transparency
    player.PlayerGui.ScreenGui.TextLabel.TextTransparency =1
end

--Connect the function to the event
textButton.MouseButton1Click:Connect(Test)

If problems, persist let me know, as there is one other thing that might be wrong with your code.

Hope this helped!