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

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

while lime > 1 do
	lime = 60
	lime = lime -1 
	game.StarterGui.main.counter.Text = lime 
	end

2 comments

0

Reading the script killed me. But for real, I can't understand this script.

0

You can't change the StarterGUI, the player's starter GUI is in a folder called PlayerGUI.

1 answer

✓ Accepted answer

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 post[^1] 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 post[^1] 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.

[^1]: Common Mistakes

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