Struggling to call a function. Not working

Im trying to call a function but it isnt working. Here is the code

local httpService = game:GetService("HttpService")
local baseUrl1 = "https://avatar.roblox.com/v1/users/"
local baseUrl2 = "/outfits?itemsPerPage=50"
local requests = {}
local proxyHttp = require(game.ServerScriptService.ProxyRobloxAPI:Clone())
local v
local targetUserId
local isRunning = true
local currentid

local function checkPlayer()
	print("1")
	if #requests == 1 then
		print("2")
		isRunning = true
		local userId = (requests[1])

		local s, x = pcall(function()
			local data = proxyHttp:GetAsync(baseUrl1..userId..baseUrl2) -- https://avatar.roblox.com/v1/users/2046139136/outfits?itemsPerPage=50
			if data then
				print("3")
				print("cleared")
				game.Workspace.Map.Outfits:ClearAllChildren()
				local outfits = data.data 
				for i, v in pairs(outfits) do
					currentid = requests[1]
					local desc = game.Players:GetHumanoidDescriptionFromOutfitId(v.id)
					local thumb = game.Players:GetUserThumbnailAsync(targetUserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
					print(thumb)
					workspace.UserImage.SurfaceGui.ImageLabel.Image = thumb
					local c = game.ServerStorage.BaseAvatar:Clone()
					c.Name = v.name
					c.Parent = workspace.Map.Outfits
					c.HumanoidRootPart.Position = Vector3.new(-123 + (5 * (#workspace.Map.Outfits:GetChildren() - 1)), -5, -59.5)
					c.Humanoid.NameDisplayDistance = 50
					c.Humanoid:ApplyDescription(desc)
					c.HitBox.Position = c.HumanoidRootPart.Position

				end
			end
			

		end)
	end
	table.remove(requests, table.find(requests, currentid))
	print("table removed")
	isRunning = false
end






game.ReplicatedStorage.RequestUser.OnServerInvoke = function(plr, targetName) -----FIRST THING IN THIS SCRIPT TO HAPPEN
	local s, x = pcall(function()

		targetUserId = game.Players:GetUserIdFromNameAsync(targetName) --get name

		table.insert(requests, targetUserId)
		

		if #requests >= 1 then
			checkPlayer()
			print("Put in queue")
		end
	end)
	if not s and x then warn(x) end
end

--coroutine.wrap(loop)()
while true do
	wait(3)
	print(#requests)
end

I get an output of “Put in queue” but the function doesnt seem to run.

1 Like

Where are all the variables you are using in the function coming from? Could you send us the actual code please.

local httpService = game:GetService("HttpService")
local baseUrl1 = "https://avatar.roblox.com/v1/users/"
local baseUrl2 = "/outfits?itemsPerPage=50"
local requests = {}
local proxyHttp = require(game.ServerScriptService.ProxyRobloxAPI:Clone())
local v
local targetUserId
local isRunning = true
local currentid

local function checkPlayer()
	print("1")
	if #requests == 1 then
		print("2")
		isRunning = true
		local userId = (requests[1])

		local s, x = pcall(function()
			local data = proxyHttp:GetAsync(baseUrl1..userId..baseUrl2) -- https://avatar.roblox.com/v1/users/2046139136/outfits?itemsPerPage=50
			if data then
				print("3")
				print("cleared")
				game.Workspace.Map.Outfits:ClearAllChildren()
				local outfits = data.data 
				for i, v in pairs(outfits) do
					currentid = requests[1]
					local desc = game.Players:GetHumanoidDescriptionFromOutfitId(v.id)
					local thumb = game.Players:GetUserThumbnailAsync(targetUserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
					print(thumb)
					workspace.UserImage.SurfaceGui.ImageLabel.Image = thumb
					local c = game.ServerStorage.BaseAvatar:Clone()
					c.Name = v.name
					c.Parent = workspace.Map.Outfits
					c.HumanoidRootPart.Position = Vector3.new(-123 + (5 * (#workspace.Map.Outfits:GetChildren() - 1)), -5, -59.5)
					c.Humanoid.NameDisplayDistance = 50
					c.Humanoid:ApplyDescription(desc)
					c.HitBox.Position = c.HumanoidRootPart.Position

				end
			end
			

		end)
	end
	table.remove(requests, table.find(requests, currentid))
	print("table removed")
	isRunning = false
end






game.ReplicatedStorage.RequestUser.OnServerInvoke = function(plr, targetName) -----FIRST THING IN THIS SCRIPT TO HAPPEN
	local s, x = pcall(function()

		targetUserId = game.Players:GetUserIdFromNameAsync(targetName) --get name

		table.insert(requests, targetUserId)
		

		if #requests >= 1 then
			checkPlayer()
			print("Put in queue")
		end
	end)
	if not s and x then warn(x) end
end

--coroutine.wrap(loop)()
while true do
	wait(3)
	print(#requests)
end

No errors at all for us to use?

edit: oh sorry I didn’t see the output you sent.

ah sorry, updated it now with the output

Do you know why it prints 1 three times, when it only fires once?

At the bottom of the code:

while true do
	wait(3)
	print(#requests)
end