Attempt to compare function and number

  1. What do I want to achieve?
    I want my module script to return the suitable rank for the player depending on the level they are on without erroring.

  2. What is the issue?
    On line 27 of the modulescript, I keep on getting the error “Attempt to compare function and number.”, with line 27 being this:

if v <= Level then

and the whole function within the module being this:

function thing.ReturnRank(Level)
	for i,v in pairs(thing) do
		if v <= Level then
			return i
		end
	end
end

Help?

Btw. I’m sending the player’s level to the module script, so the server script isn’t the problem

Thanks in advance

I see two possible causes which will cause the problem:

  1. Your passing a function through Level, or
  2. List thing contains a function

Check both Level and the list thing to make sure that Level isn’t a function and the list thing doesn’t contain a function.

Erm. Yeah the list thing does contain a function.

This one:

function thing.ReturnRank(Level)
	for i,v in pairs(thing) do
		if v <= Level then
			return i
		end
	end
end


List:

local thing = {
	["Newbie"] = 1,
	
	["Beginner"] = 2,
	["Noob"] = 3,
	["Intermediate"] = 4,
	["Advanced"] = 5,
	["More Advanced"] = 6,
	["Newbie Master"] = 7,
	
	["Beginner Master"] = 8,
	["Noob Master"] = 9,
	["Master"] = 10,
	["Chaos Master"] = 20,
	["Newbie God"] = 40,
	["Beginner God"] = 60,
	["Noob God"] = 80,
	["Ultimate"] = 100,
	["Insane"] = 200,
	["Unbelievable"] =500,
	["Tryhard"] = 2000,
	["Almost Like  The Creator"] = 10000000
}

The level is definitely not a function, it’s a value of a number value. So it must be the fact that its including the function in its loop. Thanks for showing me where I messed up