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
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
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.