New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

Changing the text using an touch function script?

Asked by 4 months 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?")
   game.StarterGui.TextLabel.Text = ("Joe Mama")


...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
Answered by
Feahren 2005 Moderation Voter Community Moderator
4 months ago
Edited 4 months 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!


Answer this question