Why is it not getting the players userID?

This prints ‘-1’ which obviously isn’t a userID, any idea what I’m doing wrong?

local winnerId = winner.UserId
					print(winnerId)

Are you testing in local server? Just play the game normally and it will work. Local servers give negative userIds to not interfere with actual ids

2 Likes

Thanks, will try out now :slight_smile:

fgdghfdgdf

1 Like

I keep getting this error even when I just give it a straight up userID, any idea why, I’d really appreciate any help.

‘ServerScriptService.Arena1Script:173: attempt to concatenate string with nil’

--This is the line the error is happening on
return "catalog.roproxy.com/v1/search/items/details?Category=Clothing&Subcategory=ClassicTShirts&Limit=30&CreatorTargetId="..UserId.."&Cursor="..Cursor

Calling the function:

local userTShirts = GetUserGeneratedTShirts(46202592)

Whole function incase you need it:

local function FormatUserGeneratedTShirtsEndpoint(UserId, Cursor)
						Cursor = Cursor or nil
						return "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
2 Likes

That means either UserId or Cursor are nil. Make sure they both actually exist before attempting to concatenate with them

Cursor = Cursor or nil
This line may be problematic for that reason

1 Like

Thank you, any idea what I am supposed to put for cursor? I don’t actually know what it means as someone helped my with my script.

It’s for an API endpoint. API endpoints require specific values in their URIs to properly request the right information. You’ll have to read about the specific API, try throwing the link in Google to see if you can discover documentation

Testing in studio will always bear ‘-1’ UserId.

You could implement a check if you are in studio and use a dummy value accordingly:

local RunService = game:GetService("RunService")
local winnerId = (not RunService:IsStudio() and winnerId) or 16012710
2 Likes

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