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

Help with for loop?

Instead of going from 30 to 1 by counting down, it goes from 1- inf (infinity)

	for i = 30,1 do --Intermission
		GameTime = ValuesFolder:WaitForChild("GameTime")
		GameTime.Value = i
		wait(1)
	end

1 answer

✓ Accepted answer

When Counting Down, You have To Subtract the i.

You can count up with a for loop the same way you were trying with a switch in value ordering, like so,

for i = 1,30 do --Intermission--counts up
    GameTime = ValuesFolder:WaitForChild("GameTime")
    GameTime.Value = i
    wait(1)
end

This is the same as,

for i = 1,30,1 do --Intermission
    GameTime = ValuesFolder:WaitForChild("GameTime")
    GameTime.Value = i
    wait(1)
end

The extra one is basically always there unless altered. This is what I gets added by each time. So, in order to make the loop count down, we make the number a negative,

for i = 30,1,-1 do --Intermission--counts down
    GameTime = ValuesFolder:WaitForChild("GameTime")
    GameTime.Value = i
    wait(1)
end

That's how I remember anyway.

Good Luck!

2 comments

0

Thanks! I knew how to add the extra i, but I did not think about it.

0

Extra "1", sorry.

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