Here's the code for the both script/localscript, i've tried using both script types.
local myTextLabel = game.StarterGui.ScreenGui.TextLabel -- The Gui that i'm trying to change local myPart = script.Parent -- The Part that is going to be touched and change the Gui myPart.Touched:Connect(function(player) myTextLabel.BackroundTransparency = 0 end)
I've tried debugging and everything, and the localscript/script is in game.Workspace, i've tried to put the localscript/script everywhere else to see the results, but nothing seems to work.
It should work 100%, but i'm very confused as to how the backroundTransparancy = 0 doesn't work on the touched event, considering i've debugged the touched event and all that.
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.
--A server script, in ServerScriptService, for example local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Remote = Instance.new("RemoteEvent") Remote.Parent = ReplicatedStorage --you can also have such remotes pre-made in your explorer (I usually do this, so I can fully visualize my projects) local Trigger = workspace.Trigger Trigger.Touched:Connect(function(Part) local Player = Players:GetPlayerFromCharacter(Part.Parent) -- find player who touched if Player then --make sure it really is a player Remote:FireClient(Player) --send to local script with required argument (the player we are referring to) end end) --A local script. You can put it in any appropriate place, but I try to keep my primary client-side code in StarterPlayerScripts local Players = game:GetService("Players") local Player = Players.LocalPlayer local ReplicatedStorage = game:GetService("ReplicatedStorage") local Remote = ReplicatedStorage:WaitForChild("RemoteEvent") --wait for server to add remote Remote.OnClientEvent:Connect(function() --listen for :FireClient() from server local Gui = Player.PlayerGui:FindFirstChild("ScreenGui") if Gui then --ensure it exists 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!