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

This script for a countdown from 60 seconds is not working?

Asked by 7 years ago
Edited 7 years ago
while lime > 1 do
    lime = 60
    lime = lime -1 
    game.StarterGui.main.counter.Text = lime 
    end
0
Reading the script killed me. But for real, I can't understand this script. j236 26 — 7y
0
You can't change the StarterGUI, the player's starter GUI is in a folder called PlayerGUI. phxtn 154 — 7y

1 answer

Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
7 years ago

Your script has a few issues:

  • For one, you set lime to be 60 on each iteration, effectively creating an infinite loop.
  • You don't have any sort of delay, so even if it wasn't an infinite loop it wouldn't be very effective.
  • You make changes to StarterGui, rather than PlayerGui.

When creating a countdown, you generally want to use a numeric for. I'll let the wiki explain what that is. You can easily change your script to use a numeric for:

for lime = 60, 1, -1 do
    game.StarterGui.main.counter.Text = lime
end

That handles the first problem, but there are still two problems with this. The first one is a really common mistake. You used StarterGui to try to change the contents of players' GUIs. Check out the blog post1 for an explanation of that.

The second issue is that there's no delay-- the loop will almost instantly finish because you don't wait. This can be easily remedied:

for lime = 60, 1, -1 do
    game.StarterGui.main.counter.Text = lime
    wait(1)
end

This doesn't fix the StarterGui issue, though. Depending on whether you have Filtering enabled or not, you can go about fixing this differently. Personally, I'd prefer using a RemoteEvent either way. The blog post1 shows you a different way to go about it, if you prefer that method. I'm going to let you decide how to go about doing that.

Hope this helped.

P.S.: In the future, please explain your problem in full (i.e., explain exactly what happens) using your post, not only the title.

Ad

Answer this question