When changing TextLabel text, the text property updates but doesn't update on the screen

I am relatively new to scripting and have decided to make some really basic minigames as a learning opportunity. Making a game where you’re instructed to stand on a specific colour, if you fail you die. So when I try to change the text on screen, the TextLabel text property changes but the text on the screen does not.
Here’s some images if it helps
gui
text

Here is the script.

local blue = game.Workspace.Game.Blue
local yellow = game.Workspace.Game.Yellow
local red =  game.Workspace.Game.Red
local green =  game.Workspace.Game.Green

local colours = {
	blue,
	yellow,
	red,
	green
}

local chosenColour = math.random(1, #colours)

-- Start game
wait(5)
print("Wait over")
game.StarterGui.MainGUI.GameTextFrame.TextLabel.Text = "Stand on.. "..colours[chosenColour].Name

And here is the GUI in the Explorer
guihelp

Apologies if this is really basic and I have overlooked something. Sorry if I haven’t explained this well either. I have looked for the past hour on the Developer Hub and the Developer Forum, have found the issue (appears to be something to do with PlayerGUI or using a LocalScript), but I just can’t understand it lol. When explaining, can you dumb dumb dumb this down for me? Thanks

Everything in StarterGui is replicated (cloned into) every player that is in the game, so whenever you try and make changes to something using StarterGui, you usually won’t see the results, because it wasn’t cloned into PlayerGui (the gui that the player will actually see).

To get around this, you should use Player.PlayerGui. If this is in a ServerScript (normal script), you’ll have to use the Players.PlayerAdded event, and then use a for loop to loop through all the players in the game.

for i, v in pairs(game.Players:GetPlayers()) do
The above line of code is what you’ll use to loop through the players in the game.

local playerGui = v.PlayerGui
This line of code will get each player’s PlayerGui.

PlayerGui.MainGUI.GameTextFrame.TextLabel.Text = “Your text here”
Finally, this line of code will change each player’s GameTextFrame’s text to your desired text.

This should work alright. Let me know if you encounter any problems.

Edit: In case I explained some things poorly, here are some resources from the DevHub:
PlayerGui
StarterGui
Timer and Game Status

3 Likes

Getting this error: GetPlayers is not a valid member of DataModel “Game” - Server - MainScript:19

I understand the code you’re typing though which is the important part and thank you for explaining it. What should I do to fix the error?

Sorry put Players after game and see if that works.

game.Players:GetPlayers()

Perfect, thank you! I really appreciate your help

1 Like

GetPlayers() is a function of the Players service, not the game, so that is why you were getting that error I think.

1 Like