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?
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!
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?