Attempt to index nil with number

Now I get attempt to compare number < Instance Code: if value < lastValue then --Compare the value

What type is value when you loop through the table tab?

Pretty sure it’s not a number, but you try to force it to be one using tonumber(). That will result in nil which you then try to index to compare it to lastValue.

Comment out line 19 in your original script and see what happens.

Now it print’s “6 looped” and “7 looped”.

I mean this line value = tonumber(value). Comment it out so it doesn’t execute.

This is your current for-loop. I replaced your comments with my own.

	for index, value in pairs(tab) do
		value = tonumber(value) --Here 'value' becomes 'nil' because 'value' is actually another table which can't be converted into a number
		lastValue = tab[index - 1] or -50
		
		if value[2] < lastValue then --Because 'value' is 'nil' you can't index it. This throws the error "attempt to index nil..."
			tier = value[2]
		end
	end

So, comment out the offending line and see what happens.

Same thing. :confused:

Summary

fsdesfdgasdfvgsdsdfadfsdsfvsdsdv

You are trying to index “value” as a table, here:

However, you are assigning “value” to a number value here:

Therefore it is resulting in an error, since you can’t change a table to a number. You probably meant to pass in value with an index to a number.

value = tonumber(value[2])

Sorry for the late reply. I was changing some stuff with my pc. This works!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.