Table returning nil

Hi, I am making a module script that returns a UiGradient but I ran into an error with my script:

module.Rarity = function(rarity)
	print(rarity)--Prints the correct rarity eg. 4
	local numbers = {[1]="One",[2]="Two",[3]="Three",[4]="Four",[5]="Five",[6]="Six",[7]="Seven",[8]="Eight",[9]="Nine",[10]="Ten",[11] = 'Eleven'}
	print(numbers[rarity]) --Prints nil
	local TxT = numbers[rarity] --Error here
	
	return script:WaitForChild(TxT):Clone()
end

The error is that when I am trying to get the Worded version of the number from the table it returns nil .
The error is “Argument 1 missing or nil”. Any help will be greatly appreciated :smiley:

is rarity a string or a number?

Is rarity a string? If not, you need to convert them to numbers:

module.Rarity = function(rarity)
    rarity = tonumber(rarity)
	print(rarity)--Prints the correct rarity eg. 4
	local numbers = {[1]="One",[2]="Two",[3]="Three",[4]="Four",[5]="Five",[6]="Six",[7]="Seven",[8]="Eight",[9]="Nine",[10]="Ten",[11] = 'Eleven'}
	print(numbers[rarity]) --Prints nil
	local TxT = numbers[rarity] --Error here
	
	return script:WaitForChild(TxT):Clone()
end
1 Like

Does it print rarity when you print it?
What does it print?
Also how are you calling it, through module:Rarity() or module.Rarity()?