Issue with player thumbnails

Guys I actually dont know the issue with my code. The thumbnail displaying/grabbing just grabs default thumbnails and only sometimes. This is a local script and at the end of every segment the client receieves a 2d array of pairs.

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local function bracketDisplay(list, maybe)
	print("Bracket list received:", list)

	local function GUI(round)
		local bracketsGui = playerGui:WaitForChild("Brackets"):WaitForChild("Frame")
		local thumbnailType = Enum.ThumbnailType.HeadShot
		local thumbnailSize = Enum.ThumbnailSize.Size420x420

		if round == 5 then
			local username1 = list[1]
			local success1, userId1 = pcall(function()
				return Players:GetUserIdFromNameAsync(username1)
			end)
			if success1 then
				local thumb1
				local successThumb1 = pcall(function()
					thumb1 = Players:GetUserThumbnailAsync(userId1, thumbnailType, thumbnailSize)
				end)
				if successThumb1 then
					bracketsGui:WaitForChild("Winner").Image = thumb1
				end
			end

		elseif round == 4 then
			local v = list[1]
			local username1 = v[1]
			local success1, userId1 = pcall(function()
				return Players:GetUserIdFromNameAsync(username1)
			end)
			if success1 then
				local thumb1
				local successThumb1 = pcall(function()
					thumb1 = Players:GetUserThumbnailAsync(userId1, thumbnailType, thumbnailSize)
				end)
				if successThumb1 then
					bracketsGui:WaitForChild("4"):WaitForChild("1"):WaitForChild("1").Image = thumb1
				end
			end
			if v[2] then
				local username2 = v[2]
				local success2, userId2 = pcall(function()
					return Players:GetUserIdFromNameAsync(username2)
				end)
				if success2 then
					local thumb2
					local successThumb2 = pcall(function()
						thumb2 = Players:GetUserThumbnailAsync(userId2, thumbnailType, thumbnailSize)
					end)
					if successThumb2 then
						bracketsGui:WaitForChild("4"):WaitForChild("2"):WaitForChild("2").Image = thumb2
					end
				end
			end
		else
			local frame = 0
			local number = 0
			for i, v in ipairs(list) do
				number += 1
				local roundFolder = bracketsGui:WaitForChild(tostring(round))
				local frameFolder
				if frame == 0 then
					frameFolder = roundFolder:WaitForChild(tostring(1))
					frame = 1
				elseif frame == 1 then
					frameFolder = roundFolder:WaitForChild(tostring(2))
					frame = 2
				elseif frame == 2 then
					frameFolder = roundFolder:WaitForChild(tostring(1))
					frame = 1
				end
				local matchFrame = frameFolder:WaitForChild(tostring(number))
				local username1 = v[1]
				local success1, userId1 = pcall(function()
					return Players:GetUserIdFromNameAsync(username1)
				end)
				if success1 then
					local thumb1
					local successThumb1 = pcall(function()
						thumb1 = Players:GetUserThumbnailAsync(userId1, thumbnailType, thumbnailSize)
					end)
					if successThumb1 then
						matchFrame:WaitForChild("1").Image = thumb1
					end
				end
				if v[2] then
					local username2 = v[2]
					local success2, userId2 = pcall(function()
						return Players:GetUserIdFromNameAsync(username2)
					end)
					if success2 then
						local thumb2
						local successThumb2 = pcall(function()
							thumb2 = Players:GetUserThumbnailAsync(userId2, thumbnailType, thumbnailSize)
						end)
						if successThumb2 then
							matchFrame:WaitForChild("2").Image = thumb2
						end
					end
					number = 0
				end
			end
		end
	end


	local len = #list
	if len == 1 then
		GUI(4)
	elseif len == 2 then
		GUI(3)
	elseif len > 2 and len <= 4 then
		GUI(2)
	elseif len > 4 and len <= 8 then
		GUI(1)
	elseif maybe then
		GUI(5)

	end
end

local function selfDisplay(list)
	print("Self duel received:", list)
end

game:GetService("ReplicatedStorage").Brackets.OnClientEvent:Connect(bracketDisplay)
game:GetService("ReplicatedStorage").SelfDuel.OnClientEvent:Connect(selfDisplay)

1 Like