Bad argument #1 (table expected, got nil)

I am trying to get the players rap

but i keep getting this error

bad argument #1 (table expected, got nil)

my code:

local Tables = {}
local HttpService = game:GetService("HttpService")


function Tables:GetAccountAge(plr, NumberValue)
	local plrAccountAge = tostring(plr.AccountAge)
	
	NumberValue = plrAccountAge
	
	return NumberValue and plrAccountAge
end

function Tables:GetAccountRAP(plr, NumberValue)
	local UserID = plr.UserId
	local URL = string.format("https://inventory.rprxy.xyz/v1/users/%d/assets/collectibles?sortOrder=Asc&limit=100", UserID)
	local Data = HttpService:GetAsync(URL)
	local DecodedData = HttpService:JSONDecode(Data)
	local TotalRAP = 0
	local tables = {}
	
	
	
	for _, Item in ipairs(DecodedData.Data) do -- the line where it errors
    	TotalRAP = TotalRAP + Item.RecentAveragePrice
	end
	
	NumberValue = TotalRAP
	
end

return Tables

I dont know why is it getting errors

but why would it expect a table instead of a string

by the way i wrote this in a Module Script

i have tried the table method but since i have no limited it is 0

even on my other account went on to test that has a limited and returns 0

Then how am i going to loop through all the items i have in my inventory

DecodedData.data should be lowercase. The result’s fields are all in camelCase.

local Tables = {}
local HttpService = game:GetService("HttpService")

function Tables.GetAccountRAP(plr)
	local UserID = plr.UserId
	local URL = string.format("https://inventory.rprxy.xyz/v1/users/%d/assets/collectibles?sortOrder=Asc&limit=100", UserID)
	local Data = HttpService:GetAsync(URL)
	local DecodedData = HttpService:JSONDecode(Data)
	local TotalRAP = 0
	
	for _, Item in ipairs(DecodedData.data) do
    	TotalRAP = TotalRAP + Item.recentAveragePrice
	end
	
	return TotalRAP
end

return Tables

Also, you should avoid using the : notation if you are not using OOP.

3 Likes

works thank you for helping me