Why does this function return the same thing everytime?

I have a function that is supposed to get all of a users t-shirts and put the ID’s in a table, but no matter the player it always returns the same three t shirts. Any ideas why this is?

local function getUserGeneratedTShirtsRecursive(username, tshirts, cursor)
						tshirts = {}
						cursor = ""
						local requestUrl = baseUrl:format(username, cursor)
						local success, result = pcall(function()
							return http:GetAsync(requestUrl)
						end)

						if success then
							if result then
								local success2, result2 = pcall(function()
									return http:JSONDecode(result)
								end)

								if success2 then
									if result2 then
										for _, tshirt in ipairs(result2.data) do
											table.insert(tshirts, tshirt.id)
										end

										cursor = result2.nextPageCursor
										if cursor then
											return getUserGeneratedTShirtsRecursive(username, tshirts, cursor)
										else
											return tshirts
										end
									end
								else
									warn(result)
								end
							end
						else
							warn(result)
							return getUserGeneratedTShirtsRecursive(winnerName)
						end
					end
					
					local userTShirts = getUserGeneratedTShirtsRecursive(winnerName)

On the line

return getUserGeneratedTShirtsRecursive(winnerName)

did you mean to put username? Although this probably won’t fix your issue.

1 Like

Ah i forgot about that line I was meant to delete it thanks, but no, thats not the issue

What is the value of baseUrl?

1 Like

local baseUrl = “https://catalog.roproxy.com/v1/search/items/details?Category=3&Subcategory=55&CreatorName=roblox&salesTypeFilter=1

Looks like the Roblox catalog API is having problems. After doing some research, it looks like this works:

catalog.roblox.com/v1/search/items/details?Category=Clothing&Subcategory=ClassicTShirts&Limit=30&CreatorTargetId=46202592&Cursor=

You could use it like this (untested):

local Http = game:GetService("HttpService")

local function FormatUserGeneratedTShirtsEndpoint(UserId, Cursor)
	Cursor = Cursor or ""
	return "https://www.catalog.roproxy.com/v1/search/items/details?Category=Clothing&Subcategory=ClassicTShirts&Limit=30&CreatorTargetId="..UserId.."&Cursor="..Cursor
end
local function TableConcat(TableA, TableB)
	local TableC = {}
	for i, v in ipairs(TableA) do
		table.insert(TableC, v)
	end
	for i, v in ipairs(TableB) do
		table.insert(TableC, v)
	end
	return TableC
end
local function GetUserGeneratedTShirts(UserId, Limit, Cursor)
	local TShirts = {}
	local Endpoint = FormatUserGeneratedTShirtsEndpoint(UserId, Cursor)
	local Success, Result = pcall(function()
		return Http:GetAsync(Endpoint)
	end)
	if not Success then
		warn("Unable to get t-shirts from API: "..Result)
		return TShirts
	end
	local Success2, Result2 = pcall(function()
		return Http:JSONDecode(Result)
	end)
	if not Success2 then
		warn("Unable to decode response from t-shirts API: "..Result2)
		return TShirts
	end
	for _, TShirt in ipairs(Result2.data) do
		table.insert(TShirts, TShirt.id)
	end
	if #TShirts >= Limit then
		return TShirts
	else
		Cursor = Result2.nextPageCursor
		if Cursor then
			local MoreTShirts = GetUserGeneratedTShirts(UserId, Limit, Cursor)
			return TableConcat(TShirts, MoreTShirts)
		else
			return TShirts
		end
	end
end
1 Like

Thank you so much, i’ll test it out later and let you know if it works, I really appreciate your help :slight_smile:

Hi, I have just tested the script and I was just wondering what I pass into the function for the variable ‘cursor’. Before I only passed in the playerID but I think this script gives an error unless a value for cursor is passed through.

Sorry, I edited my script. You should be able to pass in nil, or nothing now.

1 Like

Thanks, ill try it out :slight_smile:

fdnsjkfnsdjkfsd

Just got this error message ’ Unable to get t-shirts from API: URL must be http’

I edited my script again, looks like it needs to start with https://.

1 Like

Sorry, another error ‘ServerScriptService.Arena1Script:205: attempt to compare nil <= number’
Sorry I keep sending these to you, I’m still new to scripting

Did you pass a number for Limit?

1 Like

Thank you so much man, its working, i’ve been trying to fix the bug for days, I really appreciate your help :slight_smile:

1 Like

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