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

Changing the text using an touch function script?

Asked by 4 years ago

I'm trying to change what the TextLabel says using a touch event script. I've tried this...

function Touch()
   game.StarterGui.TextLabel.Text = ("Who is Joe?")
   wait(5)
   game.StarterGui.TextLabel.Text = ("Joe Mama")
end

script.Parent.Touched:connect(Touch)

...but that did not work. It only stayed on Who is Joe? But it never got to Joe Mama. Do any of you know how this is done?

1 answer

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

StarterGui is actually a replication Service—or container. Anything within it is actually transferred to another folder called PlayerGui, where the authentic GUIs are actually stored, and updated in real-time.

Trying to address the UI from StarterGui will modify the respective descendant, however, it will not replicate, so for your Script to actually make amendments to the GUI you desire, you need to write this instead:

local Player = game.Players.LocalPlayer -- PlayerGui resides in the Client
local PlayerGui = Player:WaitForChild("PlayerGui")
local TextLabel = PlayerGui:WaitForChild("TextLabel")

TextLabel.Text = "Hello!"

Hope this helped! Remember to accept this answer if so!

Ad

Answer this question