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

How to avoid making else if's on a script?

How do i avoid making 10 different else ifs for a group??

elseif Rank == 1 then

elseif Rank == 2 then
	
elseif Rank == 3 then

Then it goes on and on. How do make this script smaller?

1 answer

✓ Accepted answer

My favorite method is using tables, you can assign values to each position of the table, I am not going to be explaining them so I recommend just googling them on lua.org or on the roblox dev wiki.

Here's a small code example:

local tab = {"Blue", "Red", "Yellow"} -- 1 = Blue, 2 = Red, 3 = Yellow

color = tab[number] -- if it's 1 ==> Blue, etc.

1 comment

0

Thank you.

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