✓ Accepted answer
First of all, it should be a server script. Second of all, this code snippet is doing exactly what it's supposed to do. It's changing the BackgroundTransparency of the instance. However, this instance is being changed inside StarterGui. How does this service work?
When a player loads into the game, the contents of the StarterGui are cloned into a local folder inside the player, called PlayerGui. This means that the code you are running will not actually be noticed until your player reloads (such as if you reset).
To address this issue, you need to actually access the PlayerGui inside the player. Now, you will need to use a LocalScript to achieve this, but the .Touched event should be run on the server. Thus, you are going to have to use a RemoteEvent to make this cross-communication possible. Follow along with the examples below to see how this is done.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = Instance.new("RemoteEvent")
Remote.Parent = ReplicatedStorage
local Trigger = workspace.Trigger
Trigger.Touched:Connect(function(Part)
local Player = Players:GetPlayerFromCharacter(Part.Parent)
if Player then
Remote:FireClient(Player)
end
end)
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("RemoteEvent")
Remote.OnClientEvent:Connect(function()
local Gui = Player.PlayerGui:FindFirstChild("ScreenGui")
if Gui then
Gui.TextLabel.BackgroundTransparency = 0
end
end)
The idea of a RemoteEvent is rather important. I recommend reading the wiki page for further help on the matter. As always, let me know if you have any questions, and good luck!
2 comments
You will need remote events
I've went with the simple method of just changing the "Frame" to visible = false/true. Seems to work normally, but thank you gioni01 for the in depth explanation !