Text on Gui is not updating

Hi! I’m having a bit of trouble with my script. I’m fairly new to scripting, so sorry if it’s something small that I missed.
The print() function works as expected, but, it doesn’t update the text on the UI. No errors in the output either. Any help?

Script:

local TitleScreen = game.StarterGui.TitleScreen

local StarterGui = game:GetService(“StarterGui”)

count = script.Parent.Value.Value

repeat

count = count + 1

wait(0.5)

print(count)

TitleScreen.LoadingFrame.Loading.Text = count

until count == 100

7 Likes

This would be because you’re updating the original GUI inside of StarterGui:

When a player joins the game, the contents of StarterGui are copied and placed inside of the Player Instance in game.Players.

In order to get this to work, you’ll need to migrate all of this code over to a LocalScript, and change…

local TitleScreen = game.StarterGui.TitleScreen

to

local TitleScreen = script.Parent

And then place the LocalScript inside of your ScreenGui TitleScreen.

Hope this helps!

13 Likes

That works, thanks! 30characters

2 Likes

For future reference, it’s bad practice to space everything out in a script like that. You should also use tabs when using things like repeat and function

Ex.)

local TitleScreen = script.Parent
local count = 0 -- Initialize a new variable count that equals 0

repeat
     count = count + 1
     wait(0.5)
     TitleScreen.LoadingFrame.Loading.Text = count
until count == 100

You also can’t set variables (in your case count) to InstanceValue.Value, as this will just set the variable one time to equal the number, and will not update with that property.

Ex.)

local variable0 = workspace.NumberValue.Value
local variable1 = workspace.NumberValue

variable0 = variable0 + 1
print(workspace.NumberValue.Value) -- Will print 0, not 1.

variable1.Value = variable1.Value + 1
print(workspace.NumberValue.Value) -- Will update the value and print 1!

However, you can avoid this altogether by just using a local variable initialized inside of the script as you saw above. InstanceValues are insecure, and can be easily changed and abused by exploiters. Avoid them whenever possible!

Again, hope this all helps.

2 Likes