Broken function?

I created a function to get the rank of a player within a group, and it looks like this when I run it:

ranking.Value = getRank(shirts.Value, player)

On this line, the script gives me an error:
INVALID ARGUMENT #3: (String expected, got nil)
On the function, there are only 2 Arguments. Does anyone know about the possible causes of this?

this needs to return a string, can you show the function?

Can you provide us more details, like showing the funcion? By the way to set ranking.Value the function should return a Value.

(my friend created this function)

local getRank = function(shirtsBought, playerGuy)
	
	if shirtsBought == 0 then
		return "Supporter"
	elseif shirtsBought >= 3 then
		if shirtsBought >=5 then
			if shirtsBought >= 8 then
				if shirtsBought >= 11 then
					if shirtsBought >= 15 then
						if shirtsBought >= 20 then
							if shirtsBought >= 25 then
								if shirtsBought >= 30 then
									if shirtsBought >= 40 then
										local groupInfo = game:GetService("GroupService"):GetGroupInfoAsync(11352987)
										if playerGuy:GetRankInGroup(11352987) ~= (240 or 241) then
											return "CUSTOM RANK"
										end
										return groupInfo[playerGuy:GetRankInGroup(11352987)]
									end
									return "Insane Buyer"
								end
								return "Nike Obsession"
							end
							return "Demonic"
						end
						return "Legend"
					end
					return "Elite"
				end
				return "Superstar"
			end
			return "Pro"
		end
		return "Rookie"
	end	
end

i suggest you to try this

local ranks = {
	{
		["Rank name"] = "Supporter",
		["Rank level"] = 0,
	},
	{
		["Rank name"] = "Rookie",
		["Rank level"] = 1,
	},
	{
		["Rank name"] = "Pro",
		["Rank level"] = 2,
	},
}

function getRank(shirtbuy,playerguy)
	local choserank = {}
	for i,v in pairs(ranks) do
		table.insert(choserank,v)
	end
	table.sort(choserank,function(a,b)
		return a["Rank level"] > b["Rank level"]
	end)
	local playerrank = "Supporter"
	for i,v in pairs(choserank) do
		if shirtbuy >= v["Rank level"] then
			playerrank = v["Rank name"]
			break
		end
	end
	print(choserank)
	return playerrank
end

Thanks! I change the script to that.

1 Like