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

[SOLVED] Why won't my timer text update?

Asked by 7 years ago
Edited 7 years ago

I'm currently working on a game entitled "Color Rush," a round based game, and I'm currently working on the timer for when the round should end. My current script is as follows:

local Timer = game.StarterGui.ScreenGui.Timer

for i=120, 1, -1 do
    Time  = (tostring(math.floor(i / 60))..":"..tostring(i % 60))
    Timer.Text = Time
    wait(1)
end

After some troubleshooting, I've found that it's counting down, so the timer is working in the script, but it's not updating the timer to match. Why is that?

2 answers

Log in to vote
1
Answered by 7 years ago

The reason it doesn't update is because when a player joins a game, the contents of the StarterGui are copied into their PlayerGui. It's the contents of the PlayerGui that are shown, not the StarterGui. A quick fix would be:

for i=120, 1, -1 do
    local Time  = (tostring(math.floor(i / 60))..":"..tostring(i % 60))
    for i, v in ipairs(game.Players:GetChildren()) do
        v.PlayerGui.ScreenGui.Timer.Text = Time
    end
    wait(1)
end
Ad
Log in to vote
0
Answered by 7 years ago

Because you are using the 'StarterGui' which is does not hold the player gui.

To access the player gui from the server

local plrGui  = game.Players.[Some player name].PlayerGui

From a LocalScript

local plrGui = game.Players.LocalPlayer.PlayerGui

Answer this question