Attempt to iterate over a nil value

It’s this script:

local httpService = require(game.ServerStorage.HTTP)
local baseUrl1 = "https://avatar.roblox.com/v1/users/"
local baseUrl2 = "/outfits"
local requests = {}

local Players = game:GetService("Players")

local GuiPart = workspace.GuiPart
local Frame = GuiPart.SurfaceGui.Frame
local PlayerNameText = Frame.BottomFrame.PlayerName
local PlayerIconImage = Frame.MiddleFrame.PlayerIcon

local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420

local QueuePart = workspace.QueuePart
local QueueScroll = QueuePart.SurfaceGui.Frame.ScrollingFrame

local QueueTemplate = script.Template

local CurrentRequested

local checkPlayer = function()
	if #requests >= 1 then
		local userId = (requests[1])
		local data = httpService.getasync(baseUrl1..userId..baseUrl2)
		if data then
			CurrentRequested = userId
			local name
			pcall(function ()
				name = Players:GetNameFromUserIdAsync(userId)
			end)
			local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)

			PlayerNameText.Text = name
			PlayerIconImage.Image = content


			game.Workspace.Map.Outfits:ClearAllChildren()
			print(data)
			local outfits = data.response.data
			for i, v in outfits do
				local desc = game.Players:GetHumanoidDescriptionFromOutfitId(v.id)
				local c = game.ServerStorage.BaseAvatar:Clone()
				c.Name = v.name
				c.Parent = workspace.Map.Outfits
				c.HumanoidRootPart.Position = Vector3.new(workspace.StartingPoint.Position.X + (5 * (#workspace.Map.Outfits:GetChildren() - 1)), workspace.StartingPoint.Position.Y + 2.5, workspace.StartingPoint.Position.Z)
				c.Humanoid.NameDisplayDistance = 50
				c.Humanoid:ApplyDescription(desc)
				c.HitBox.Position = c.HumanoidRootPart.Position
			end
			table.remove(requests, table.find(requests, userId))
			QueueScroll:FindFirstChild("1"):Destroy()
			local Items = 0
			for _, Child in ipairs(QueueScroll:GetChildren()) do
				if Child:IsA("Frame") then
					Items += 1
				end
			end
			
			for i = 1, Items do
				for _, Child in ipairs(QueueScroll:GetChildren()) do
					if Child:IsA("Frame") then
						Child.Name = i
					end
				end
			end
		end
	end
end


local loop = function()
	while task.wait(60) do
		if #requests >= 1 then
			checkPlayer()
		else
			repeat game:GetService("RunService").Heartbeat:Wait() until #requests >= 1
		end
	end
end

game.ReplicatedStorage.RequestUser.OnServerInvoke = function(plr, targetName)
	local targetUserId = game.Players:GetUserIdFromNameAsync(targetName)
	if targetUserId ~= nil then
		local isOnRequests = false
		for i, v in pairs(requests) do
			if v == targetUserId then
				isOnRequests = true
				break
			end
		end
		if isOnRequests == false then
			if not table.find(requests, targetUserId) then
			table.insert(requests, targetUserId)
		
			QueueScroll:ClearAllChildren()
			
			local LayoutClone = script.UIListLayout:Clone()
			LayoutClone.Parent = QueueScroll
			
			local DidAlready = {}
			for i = 1, #requests do
					print(#requests)
					print(i)
					if not table.find(DidAlready, requests[i]) then
						table.insert(DidAlready, requests[i])
						local PlayerThumbnail = Players:GetUserThumbnailAsync(requests[i], Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)

						local PlayerInfo = Players:GetNameFromUserIdAsync(requests[i])

					local NewTemplate = QueueTemplate:Clone()
					NewTemplate.Name = i
					NewTemplate.LayoutOrder = i
					NewTemplate.MainFrame.TextLabel.Text = PlayerInfo
					NewTemplate.PlayerIcon.Image = PlayerThumbnail
					NewTemplate.Visible = true
					NewTemplate.Parent = QueueScroll
						end
					end
				end
			if #requests >= 1 then
				checkPlayer()
			end
			return "Queued"
		else
			return "Already Listed"
		end
	else
		return "Doesn't Exist"
	end
end



coroutine.wrap(loop)()
1 Like