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

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

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?

1 comment

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!

2 answers

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?

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!

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