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

How would you change text in a text label using for loops?

Asked by 4 years ago
local Main = game.StarterGui.ScreenGui.Main
game.StarterGui.ScreenGui.Main.Text = "Finished loading! Welcome to "..game.Name
wait(10)
for countdown = 10,0,-1 do
    Main.Text = "Remaining time: "..countdown
end

I'm not sure on how to properly use for loops for text labels. I'm trying to do a countdown timer but it's not changing the text at all, not even to "Remaining time: ".

0
make sure there's a space on either side of ".." and see if that fixes it Benbebop 1049 — 4y

2 answers

Log in to vote
0
Answered by
Benbebop 1049 Moderation Voter
4 years ago
Edited 4 years ago

The problem is you are modifying the StarterGui which places all of its children into a new player's PlayerGui. Modifying it would only change what a new player sees. Instead make sure its in a LocalScript and put it anywhere really. Also your code was kind-of all over the place, so I sorted it out alittle.

local Main = game.Players.LocalPlayer.PlayerGui.ScreenGui.Main

Main.Text = "Finished loading! Welcome to " .. game.Name

wait(10)

for i = 10,0,-1 do
    Main.Text = "Remaining time: " .. countdown
    wait(1)
end

LocalPlayer is the client's player.

See more

0
Still doesn't work, but shows for the server. It says say Players is unknown. Danny_Will 4 — 4y
0
Looks like you forgot game. (game.Players.LocalPlayer) asgm 109 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

The reason why your text appears as 0 is because you forgot to add a wait. So here would be the new script:

local Main = game.StarterGui.Main
game.StarterGui.ScreenGui.Main.Text = "Finished loading! Welcome to "..game.Name
wait(10)
for i = 10,0,-1 do
    Main.Text = "Remaining time: "..countdown
    wait(1)
end

You see, if you do for loops without waits or any delay, you'll see the stuff inside of the loop instantly appear, not like a smooth transition.

I hope I helped!

0
Interesting. I'll definitely use this for future for loops. Danny_Will 4 — 4y
0
That wouldn't stop it from appearing altogether, it could if it causes the script to crash but it doesn't seem like that's happening. Benbebop 1049 — 4y
0
So, the loop works, but the problem is that it's showing for the server view only. Danny_Will 4 — 4y
0
Nevermind, the problem is that you are modifying the StarterGui Benbebop 1049 — 4y

Answer this question