How can you change the PlayerGui?

I’m a beginner scripter and tried changing a PlayerGui through a LocalScript by clicking a gui button and it completely creates new text for PlayerGui or clicking/touching a brick and changing it(doesn’t really matter).

Is it like:

game:GetService(“Players”).LocalPlayer:WaitForChild(“PlayerGui”).ScreenGui.TextLabel.Text = “Text”

or

game:GetService(“Players”).LocalPlayer.PlayerGui:WaitForChild:(“ScreenGui”).TextLabel.Text = “Text”

or is it completely something different?

3 Likes

Where is the localscript? If it is inside the gui you can just reference it directly with script.Parent...

This should be just about right :+1:

What you can alternatively do is put a localscript under the ScreenGui you are concerned with (in StarterGui) so that you can easily track your GuiObjects.

local ScreenGui = script.Parent
local TextLabel= ScreenGui.TextLabel
TextLabel.Text = "Text"
1 Like

you can probably find tutorials on this online which I recommend doing that before making a post, but when your changing a Gui I would define a string as your Gui you are looking for to make it easier, and then change the text from there. It would look something like this:

local ScreenGui = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")
ScreenGui.TextLabel.Text = "Text"

That would be changing a text though, if you wanted to make a new textlabel you would have to use Instance.new. It would be something like this:

local ScreenGui = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")
local NewTextLabel = Instance.new("TextLabel")
NewTextLabel.Parent = ScreenGui
NewTextLabel.Text = "Text"

Also as Blokav said you can use script.Parent if the local script is close to your textlabel, along with using GetService() is not really necessary for this.

Edit: What you had up though would still work for changing a text

7 Likes