local StarterGui = workspace.StarterGui
local ScreenGui = workspace.StarterGui.ScreenGui
local TextLabel = workspace.StarterGui.ScreenGui.Transparency
local Part1 = game.Workspace.Part1
script.Parent.Touched:Connect(function()
script.TextLabel.Transparency = 0
end)
Does this script seem to be correct?
2 answers
Make sure to grab the service of Players. This will help identifying which player's PlayerGui to work with and the variable of the part you want to work on.
You can do Instance.new() when you are trying to create the GUI once the player has touched the part:
local Players = game:GetService("Players")
local Part1 = game.Workspace.Part1
Part1.Touched:Connect(function(Player)
local ScreenGui = Instance.new("ScreenGui", Players[Player.Parent.Name].PlayerGui)
end)
ScreenGui is the instance that you want, Players[Player.Parent.Name].PlayerGui is going into Players, utilizing what the function has grabbed from part that touched Part1, finds the player's name searches that within Players.
But, to make the GUI show, you need a frame:
local Frame = Instance.new("Frame", ScreenGui)
Add another instance of TextLabel and place them inside the Frame (the Parent):
local TextLabel = Instance.new("TextLabel", Frame)
When the player does touch Part1, then we want to make the TextLabel invisible.
Now, TextLabel has three transparency properties; BackgroundTransparency and TextTransparency and TextStrokeTransparency. Let's make it easy and say that we want to make the background transparent:
TextLabel.BackgroundTransparency = 0
For now, it should look something like this:
local Players = game:GetService("Players")
local Part1 = game.Workspace.Part1
Part1.Touched:Connect(function(Player)
local ScreenGui = Instance.new("ScreenGui", Players[Player.Parent.Name].PlayerGui)
local Frame = Instance.new("Frame", ScreenGui)
local TextLabel = Instance.new("TextLabel", Frame)
TextLabel.BackgroundTransparency = 0
end)
TextLabel and Frame are something you should customize inside your script since it completely default when you make it a new instance:
Frame.Size = UDim2.new(1,0,1,0)
Frame.BackgroundTransparency = 1
Frame.BorderSizePixel = 0
TextLabel.Size = UDim2.new(0,200,0,50)
TextLabel.Position = UDim2.new(0.5,-100,0.5,-25) --Size is 200,50 so by subtracting half, it'll center.
TextLabel.Text = "Testing"
TextLabel.TextScaled = true
If you want it to add only once, you can use FindFirstChild() to see if it's there or not. Inside the parameter is the name you are looking for;
if Players[Player.Parent.Name].PlayerGui:FindFirstChild("ScreenGui") == nil then
--Add anything
end
Altogether, it should look like this;
local Players = game:GetService("Players")
local Part1 = game.Workspace.Part1
Part1.Touched:Connect(function(Player)
if Players[Player.Parent.Name].PlayerGui:FindFirstChild("ScreenGui") == nil then
local ScreenGui = Instance.new("ScreenGui", Players[Player.Parent.Name].PlayerGui)
local Frame = Instance.new("Frame", ScreenGui)
local TextLabel = Instance.new("TextLabel", Frame)
Frame.Size = UDim2.new(1,0,1,0)
Frame.BackgroundTransparency = 1
Frame.BorderSizePixel = 0
TextLabel.Size = UDim2.new(0,200,0,50)
TextLabel.Position = UDim2.new(0.5,-100,0.5,-25) --Size is 200,50 so by subtracting half, it'll center.
TextLabel.Text = "Testing"
TextLabel.TextScaled = true
TextLabel.BackgroundTransparency = 0
end
end)
Hope this helps!
1 comment
yes
local StarterGui = workspace.StarterGui
local ScreenGui = workspace.StarterGui.ScreenGui
local TextLabel = workspace.StarterGui.ScreenGui.Transparency
local Part1 = game.Workspace.Part1
script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
script.TextLabel.Transparency = 0
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
What is the script's parent?
And why is the StarterGui in the Workspace?
Hello, I was wondering if you could accept my answer? You should be able to hover over my answer and hit "Accept answer"