Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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: ".

1 comment

0

make sure there's a space on either side of ".." and see if that fixes it

2 answers

✓ Accepted answer

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

2 comments

0

Still doesn't work, but shows for the server. It says say Players is unknown.

0

Looks like you forgot game. (game.Players.LocalPlayer)

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!

4 comments

0

Interesting. I'll definitely use this for future for loops.

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.

0

So, the loop works, but the problem is that it's showing for the server view only.

0

Nevermind, the problem is that you are modifying the StarterGui

This discussion is preserved as it was. New answers, comments, and votes are closed.