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

Is there a way to make this script smaller?

Just wondering if there was a way in shortening this script, while still keeping the Value's of the Size.

function Countdown()
script.Parent.FontSize = "Size32"
wait()
script.Parent.FontSize = "Size28"
wait()
script.Parent.FontSize = "Size24"
wait()
script.Parent.FontSize = "Size18"
wait()
script.Parent.FontSize = "Size14"
wait()
script.Parent.FontSize = "Size12"
wait()
script.Parent.FontSize = "Size11"
wait()
script.Parent.FontSize = "Size12"
wait()
script.Parent.FontSize = "Size14"
wait()
script.Parent.FontSize = "Size18"
wait()
script.Parent.FontSize = "Size24"
wait()
script.Parent.FontSize = "Size28"
wait()
script.Parent.FontSize = "Size32"
end

2 answers

✓ Accepted answer

Create an array with the Sizes as indexes.

Then use a for loop to go through them.

--Create an array with  your changes
local sizes = {"Size32", "Size28", "Size24", "Size18", "Size14", "Size12", "Size11", "Size12", "Size14", "Size18", "Size24", "Size28", "Size32")

--For loop that goes through array
for x = 1, #sizes, 1 do
	wait()
	script.Parent.FontSize = sizes[x] --Assigns the index
end

The for loop will only go through the amount of indexes it has than stop.

#sizes is a cool way to return the length of an array.

Let me know if you have any other questions.

3 comments

3

You can cut the length of array in half by going forward then back. If you're being extra short you could pull the "Size" part into the loop and out of the array.

1

Even shorter, since FontSize is an Enum (http://wiki.roblox.com/index.php?title=API:Enum/FontSize), you can store its integer value instead (i.e. sizes = {11, 10, 7, 6, 5, 4, 3, 4, 5, 6, 7, 10, 11})

0

Hmm, I did not know that myself. I have yet to really delve into GUI's. Good to know though, thanks for sharing.

local function countdown()
local sizes = {32,28,24,18,14,12,11}
for i = 1,#sizes do
script.Parent.FontSize = "Size"..sizes[i]
wait()
end
for i = #sizes,1,-1 do
script.Parent.FontSize = "Size"..sizes[i]
wait()
end
end

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