How to make a "for, i =" loop work

I’m not very new to scripting, but usually the things that I script don’t really use for, i = loops. I have a small little section of script, where I’m trying to have a blinking arrow and a countdown. The countdown and the sound are working just fine, but I can’t figure out how to order it or make it work so that the arrow will become transparent then non transparent over and over. It might just be because I’m tired lol, but any help would be appreciated :slight_smile:

	for i = 10, 0, -1 do
		info.Message.Value = "Game starting in..." .. i
		map.StartArrow.Transparency = 0
		sounds.StartingArrow:Play()
		task.wait(1)
		map.StartArrow.Transparency = 1
	end

Um…? You have it so it is always transparent to 1? Maybe I am misunderstanding what you want. Set it to 0 for one of them, then the other keep it at one?

You are not seeing the arrow’s visibility change because you are setting its Transparency property to 1 after setting it to 0 with no pause in between. It really is changing, but too fast to be seen.

Your current code:

map.StartArrow.Transparency = 0
sounds.StartingArrow:Play()
map.StartArrow.Transparency = 1 -- No yield before second change.

Also, why are you setting the Transparency to 1 again after it has already been set to 1?

1 Like

Here’s a better version. That wasn’t my final one and it was in between edits my bad. But I don’t see the reason why this one isn’t working. The arrow is staying at a transparency of 0.

	for i = 10, 0, -1 do
		info.Message.Value = "Game starting in..." .. i
		map.StartArrow.Transparency = 0
		sounds.StartingArrow:Play()
		task.wait(1)
		map.StartArrow.Transparency = 1
	end

Because it goes to 1, and then repeats the loop, which makes it go back to 0 in a instant. You might need to add another task.wait() before the 0 at the start of the loop, so each get 1 second of flashing

Or split the 1 second, and make each task.wait(), 0.5 seconds instead like this:

for i = 10, 0, -1 do
          task.wait(0.5)
		info.Message.Value = "Game starting in..." .. i
		map.StartArrow.Transparency = 0
		sounds.StartingArrow:Play()
		task.wait(0.5)
		map.StartArrow.Transparency = 1
	end
1 Like

Thanks, I split it into 0.5 and made 2 seperate task.wait() and it worked

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.