Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why won't my text label update?

Asked by 3 years ago
Edited 3 years ago

Hey, I'm trying to make a script that counts down from 20 to 1 and displays it on a text label, but I can't seem to get it working. I printed the text to the output and it counts down just as it should, but the text label always stays at "Game Starting in 20...".

Here is the script, which is located in ServerScriptService:

label = game.StarterGui.Screen.Label
while true do
    x = true
    t = 20
    while x == true do
        label.Text = "Game Starting in "..t.."..."
        print(label.Text)
        t = t - 1
        if t == 0 then
            x = false
        end
        wait(1)
    end
end

Help would be appreciated, -Spacetimit

2 answers

Log in to vote
0
Answered by
2Loos 168
3 years ago
Edited 3 years ago

Well, there should be local to define label as a variable. I don't think not adding local will work with a variable anymore. Anyways, create a localscript under the TextLabel. Then add local to your variable to define it as one. Change the variable to fit the new parents and children. The adjusted script is attached below.

local label = script.Parent
local x
local t
while true do
    x = true
    t = 20
    while x == true do
        label.Text = "Game Starting in "..t.."..."
        print(label.Text)
        t = t - 1
        if t == 0 then
            x = false
        end
        wait(1)
    end
end

Some notes for you to take whenever working with Gui's.

  1. Always use LocalScript(s) when working with Gui's
  2. Always use local when defining a variable (good practice!)
Ad
Log in to vote
1
Answered by 3 years ago

The label is updating, just not for every player. For this, you'd use PlayerGui and, preferably, a LocalScript.

StarterGui is the descendant of the DataModel (game) that holds GUI objects, local scripts, etc. that are replicated to a player's PlayerGui. Both can be updated in real-time, but only one will display its changes to the player in real-time. When you're changing GUI values, or doing anything ScreenGui-related, you should always use the PlayerGui.

0
How would I go about doing this? Do I just copy paste my code into a local script and change StarterGui to PlayerGui? Spacetimit 47 — 3y
0
Pretty much, yes. DeceptiveCaster 3761 — 3y

Answer this question