How do I shorten if and elseif than adding tons of statements?

Well I’m putting a Rank text through Overhead/Billboard Gui’s and I want to shorten “if” and “elseif” statements than adding tons of them, I don’t know how to ModuleScript this too

		Clicks:GetPropertyChangedSignal("Value"):Connect(function()
			if Clicks.Value >= 5 then
				CloneOverhead.Frame.ClickRank.Text = "Pro"
			elseif Clicks.Value >= 4 then
				CloneOverhead.Frame.ClickRank.Text = "Epic"
			elseif Clicks.Value >= 3 then
				CloneOverhead.Frame.ClickRank.Text = "Medium"
			elseif Clicks.Value >= 2 then
				CloneOverhead.Frame.ClickRank.Text = "Normally"
			else
				CloneOverhead.Frame.ClickRank.Text = "Starter"
			end
		end)
1 Like

You can use Tables

3 Likes

You could pack all Ranks in to a table like so,

local ClickRanks = {
   [2] = "Normal",
   [3] = "Medium",
   [4] = "Epic",
   [5] = "Pro"
}

then you could use the Clicks value to index the corresponding rank:

Clicks:GetPropertyChangedSignal("Value"):Connect(
   function()
       CloneOverhead.Frame.ClickRank.Text = ClickRanks[Clicks.Value] or "Starter"
   end
)

Lets say the player gets 1 click, what this does is it tries to find the index 1 in the table, but fails to do so, so it returns
nil, and the or statement will check if the first variable supplied is not equal to nil or false and if it is it will return the second variable. Vica versa, if I have 5 clicks, I will be able to index the table because there is a value at table index 5 so the or statement will just return my corresponding rank

3 Likes

Thank you it works but I’m trying to turn the table to a ModuleScript how do I do it? I’m trying but it says ``
invalid argument #3 (string expected, got nil)```

where exactly is it giving you this error?