My TextLabel's text is not updating please help!

Hello, I am making a few personal projects to practice what I have learnt from watching beginner scripting tutorials. I am trying to make a script that counts the players in the server so players can see it as I added a Text Label on the top of the screen.

The script is basically supposed to be in a while loop and has a variable which gets the number of players in the server. Then there’s a Text Label on the screen which says “Number of players in game:” and then it adds the variable. Due to the fact that this is a while loop that repeats every 2 seconds, I thought the variable would update… For some reason though the variable is updating, but every time I test my game it says Number of players in server: 0… So even though the variable is updating, the number on the Text Label does not change…

(The font kind of makes the number look like an “o”)

(The numbers from the output was because I printed the variable. Meaning the variable was updating on the output, it was not updating for the GUI…)

Thank you for reading this, if you know a solution to this problem I would really appreciate it if you could reply back to me. (This was my first post and I know it probably could’ve been formatted better, sorry!)

1 Like

You don’t change the game.StarterGui location, you need to update the Player GUI, or you fire a remote event to change the text based on the players in the game. If you would like, you can do this via the client (just insert that script into a local script, in a text Label, then from there, instead of game.StarterGui.ScreenGui.Frame.TextLabel.Text, you can use script.Parent.Text

2 Likes

@VoidException is correct.

The issue is that when a player enters, the game clones your StarterGui into the corresponding Player>PlayerGui object. So what you are changing is the original but what you are seeing is the clone.
If you entered another player they would likely see an updated version with 1 instead of 0.

2 Likes

Thank you so much for your help! I’ll take this into consideration next time :+1:!