Value stays nil

Hi, I have this local script where it shows the head shot image of all the players through walls, however the image stays nill, can anyone tell me why?

Code

local Players = game:GetService("Players")

local PlayerIcons = {}

function AddIcon(Player)
	spawn(function()
		local URL, CanUse = Players:GetUserThumbnailAsync(Player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size60x60)
		PlayerIcons[Player] = URL
	end)
end

function FindIcon(Player)
	for i,v in pairs(PlayerIcons) do
		if v.Name == Player.Name then
			return v
		end
	end
	
	return nil
end

function CreateGui(Character, URL)
	local BillBoardGui = Instance.new("BillboardGui")
	BillBoardGui.Parent = Character.Head
	BillBoardGui.AlwaysOnTop = true
	BillBoardGui.Size = UDim2.new(2,0,2,0)
	
	local ImageLabel = Instance.new("ImageLabel")
	ImageLabel.Parent = BillBoardGui
	ImageLabel.Size = UDim2.new(1,0,1,0)
	
	if URL ~= nil then
		ImageLabel.Image = URL
	end
end

function CheckGui(Character)
	local BBG = Character.Head:FindFirstChild("BillboardGui")
	if BBG then
		return true
	else
		return false
	end
end

for i,v in pairs(Players:GetChildren()) do
	local Icon = FindIcon(v)
	if Icon == nil then
		AddIcon(v)
	end
end

while wait(5) do
	for i,v in pairs(Players:GetChildren()) do
		local Icon = FindIcon(v)
		if Icon == nil then
			AddIcon(v)
		end
		
		if v.Character ~= nil then
			local BBG = CheckGui(v.Character)
			if BBG == false then
				CreateGui(v.Character, Icon)
			end
		end
	end
end

Also yes I know spawn is a bad practice, ill get out the habit of using it soon :frowning:

For your PlayerIcons associative array, the items in there does not have any Name field. - You only put that “URL” into it.

Perhaps your FindIcon method is supposed to look like this?:

function FindIcon(Player)
	for i,v in pairs(PlayerIcons) do
		if i.Name == Player.Name then  -- <-- using `i.Name` instead of `v.Name`
			return v
		end
	end
	
	return nil
end