Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a brick, that when you touch it, it changes text/transparency?

Asked by
Cowgato 33
3 years ago

So here's the story, whenever a character touches a brick, I want the gui to change text/transparency, however I do not know what is wrong with my script.

script.Parent.Touched:Connect(function()
    game.StarterGui.ScreenGui.Frame.TextLabel.Text = "hellloooo"
end)

The script in the brick ^^^

0
A copy of all the stuff in StarterGui is copied into each player's PlayerGui container when they spawn. With this script, you're changing the base copy of the GUI, and not the GUI the player currently has. R1ceNice 20 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Hello.

The reason as to why you aren't seeing changes to the Frame text, is because you are changing the frame in the StarterGui, instead of the PlayerGui. The StarterGui is different compared to the PlayerGui for a very important reason. The StarterGui, as said in it's name, is what gives the player the Guis when they join, and the PlayerGui, also said in it's name, is the Guis present in the Player.

To make changes to the gui, you are required to change the gui from the PlayerGui instead. So with your script, assuming it's a serverscript, you need to get the player via the Touched function, simply done with a Players:GetPlayerFromCharacter(hit.Parent). We tend to use a hit function for the touched function, as it's used to define the player.

Now let's take your script and apply these changes:

local Players = game:GetService("Players") -- Get the players
local Part = script.Parent -- Gets the part that needs to be touched

Part.Touched:Connect(function(hit) -- Set the hit function
    local Player = Players:GetPlayerFromCharacter(hit.Parent) -- Get the LocalPlayer via the touched event
    local PlayerGui = Player:WaitForChild("PlayerGui") -- Get the PlayerGui
    PlayerGui.ScreenGui.Frame.TextLabel.Text = "hellloooo" -- Set the text from the gui in PlayerGui
end)

Hope this helps!

Ad
Log in to vote
0
Answered by
KixWater 126
3 years ago

No, you also have to make sure if a player touched the part:

local Part = script.Parent

Part.Touched:Connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum then -- Do whatever the person on top of me did

end)

Answer this question