Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can you change a textlabel with a script?

I am trying to make a game that automatically chooses maps (which I do not need help with) but there is a problem; when I try to change a textlabel in a ScreenGui with a script located anywhere (even if I make it a child of the textlabel) the script won't make it change. I put it in the script that chooses the maps, and the actual map choosing part works, but is there anything wrong with this line? It even prints but it doesn't change the label

print("castle was selected")
game.StarterGui.Status.e.Text = "The 'Castle' map has been chosen"

"Status" is the ScreenGui, and "e" is the TextLabel``

2 comments

0

Try locating the TextLabel first (local e = game.StarterGui.Status.TextLabel) and then change it to (e.Text = "----")

0

MArzalAlBuchariZ, that is basically what I did up there

2 answers

You will need to access the player gui for any changes to display because when you change it in the starter gui it won’t be visible try

local Player = game.Players.LocalPlayer local PlrGui = Player:WaitForChild(“PlayerGui”)

local your gui = PlrGu:WaitForChild:(“yourscreengui”).something

I am not a good scripter but I think you need a for loop, and change "StarterGui" to PlayerGui instead. Here is the script:

local Players = game:GetService("Players")
local player = Players:GetChildren()

for i,v in pairs(player) do
	v.PlayerGui.Status.e.Text = "The 'Castle' map has been chosen!"
end

I am not pro at scripting. I haven't tested the script above but I think it will work. If it works then let me know, if it doesn't then let me know too in the comments!

3 comments

0

It doesn't really work because it thinks that Status is not a valid member of PlayerGui

0

If it is not a valid member of PlayerGui it means either that you are accessing the contents of the PlayerGui through a Script (you should be using LocalScripts when accessing GUIs) or that you need to use :WaitForChild on Status in case it hasn't loaded yet.

0

Rheines thank you I figured out something when you said to use a localscript

This discussion is preserved as it was. New answers, comments, and votes are closed.