Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How is the if statement getting the nil value from the first part in parenthesis? (SOLVED)

Hey guys, As you can probably tell from the title, this following code keeps telling me I'm comparing a nil value to a number.

Here is the code:

local hs = game:GetService("HttpService")
local got_table = hs:GetAsync("https://search.rprxy.xyz/catalog/json?CatalogContext=1&Subcategory=2&SortAggregation=5&PageNumber=1&LegendExpanded=true&Category=2", true)
local json_table = hs:JSONDecode(got_table)
local dic_values = 0;
local common = {} -- 0 and 2,500
local uncommon = {} -- 2500 and 9,000
local rare = {} -- 9000 and 75,000
local legendary = {} -- 75000 and 500,000
local ultra_rare = {} -- 500,000 and 999,999,999,999


for i = 1, 44 do
	print("Page #"..i..":")
	repeat

	for index,value in next, json_table do -- Counts the amount of values in the dictionary.
		dic_values = dic_values + 1;
	end

	got_table = hs:GetAsync("https://search.rprxy.xyz/catalog/json?CatalogContext=1&Subcategory=2&SortAggregation=5&PageNumber=" .. i .. "&LegendExpanded=true&Category=2", true)
	json_table = hs:JSONDecode(got_table)
	until dic_values > 0

	for index, value in next, json_table do -- Prints all the values inside dictionary.
	    if ((tonumber(value.BestPrice) or tonumber(value.Price)) >= 0 and (tonumber(value.BestPrice) or tonumber(value.Price)) <= 2500) then
		print(tonumber(value.BestPrice))
	end
	end
end

print("Values are done!")

Apparently, the first part of the if statement on line #25, which is:

if ((tonumber(value.BestPrice) or tonumber(value.Price))

is giving me a nil value. I have no clue as to how that is happening because, I am using ternary and an object in catalog can't be missing both a BestPrice and a Price. So, if the first value is nil, it should just go to the next value.

Any help is appreciated and thank you, once again.

~~ KingLoneCat

3 comments

0

Could you possible print the JSON table itself as a string? I'd like to see what it has in it.

0

But, I figured it out. Apparently, for some reason in the string, the creator of the item added a comma in the number so, I had to remove that with gsub but, thanks for the attempt to help me.

1 answer

here it looks like you have an extra parenthesis. I'm not sure though so do not downvote this,

(tonumber(value.BestPrice) or tonumber(value.Price)) <= 2500) 

1 comment

0

He only copied one line from a multi-line boolean condition. If there were a syntax mistake, a corresponding error would have been produced.

This discussion is preserved as it was. New answers, comments, and votes are closed.