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

Why is the text on this GUI not changing?

Asked by 7 years ago

I have a script that changes the text of a GUI every second, as a countdown timer.

intermissionTime = 5*60
while true do
    local intermission = game.StarterGui.ScreenGui.Intermission
    local timeLeftIntermission = intermission.IntermissionTime
    intermission.Visible = true
    timeLeftIntermission.Text = intermissionTime
    intermissionTime = intermissionTime - 1
    print(timeLeftIntermission.Text)
    wait(1)
end

When I run the script, the GUI changes as it should...counting down every second from 300. But when I Play the game, it doesn't, but simply stays at 300. I added a print line to check what was going wrong, and it says that it is changing, but it isn't. This is not the first time this has happened. Why doesn't this work?

0
Using while loops for "countdowns" is unnecessary & repetitive. All you need to use is a for loop instead of a while loop: http://wiki.roblox.com/index.php?title=Loops#For TheeDeathCaster 2368 — 7y
0
That is true, but also irrelevant. The problem is not the loop; it's the GUI. The loop works fine, but the GUI isn't changing when I Play the game, though it is when I Run it. jamesarsenault 192 — 7y

3 answers

Log in to vote
0
Answered by 7 years ago

You could try something like this

time = 300 -- You can change this
for i=time,  0, -1 do
    wait(1)
    local intermission = game.StarterGui.ScreenGui.Intermission
    local timeLeftIntermission = intermission.IntermissionTime
    intermission.Visible = true
    timeLeftIntermission.Text = "Time Left "..i
end

This is basically your script, but runs on a for loop which stops when it reaches 0, you can edit the time at the top :)

Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

First, you have to link the text to a string value. What you want to do is put a string value in Replicated Storage. Next, once you have the string value, you want to connect the string with the text label. You have to enter a local script into the text label.

--The Text Label
local replicatedstorage = game:GetService('ReplicatedStorage') -- You are accessing the Replicated Storage
local status = replicatedstorage.Status -- This is what I'm naming it. You don't have to name it status

script.Parent.Text = status.Value
status.Changed:connect(function()
    script.Parent.Text = status.Value
end)

The next step is to put a script into the Service Script Storage. This is where you will begin the countdown.

Once you have it, you have to type this:

--Main Script
local replicatedstorage = game:GetService('ReplicatedStorage') -- Once again, you need to obtain Replicated Storage
local status = replicatedstorage.Status

for i = 300, 0, -1 do -- Subtracting 1 from 300 each second until it reaches 0
    status.Value = "Intermission: "..i -- Remember, i is (300, 0, -1)
    wait(1) -- Waits one seconds before subtracting 1

Hope this helps!!!

0
None of this works. The text still does not change when I Play the game, and still does change when I Run the game. jamesarsenault 192 — 7y
Log in to vote
-1
Answered by 7 years ago

You shuld try something like this:

for i = 300, -1 do

wait(1) Intermission.Text = "time left" .. i end

Answer this question