Getting a users thumbnail when they join the game

I had a script that should get a users thumbnail when they join the game, however I’m having some issues.

local ArenaToLobby = RS:FindFirstChild("ArenaToLobby")
local LobbyToArena = RS:FindFirstChild("LobbyToArena")

local backup_thumbnail = "image_string_url"
local playerThumbnails = {}

game.Players.PlayerAdded:Connect(function(player) 
	
	-- Store thumbnail from player that joined
	local content, isReady = pcall(function()
		return Players:GetUserThumbnailAsync(player.UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size150x150)
	end)
	playerThumbnails[tostring(player.UserId)] = (isReady and content) or backup_thumbnail
end)

Players.PlayerRemoving:Connect(function(player)
	-- Remove stored thumbnail from player that left
	if playerThumbnails[tostring(player.UserId)] then
		playerThumbnails[tostring(player.UserId)] = nil
	end
end)


-- These are bindable events
ArenaToLobby.Event:Connect(function()
	LobbyToArena:Fire(playerThumbnails)
end)

In a different script:

playEvent.OnServerEvent:Connect(function()
	
	local playerThumbnails = nil
	ArenaToLobby:Fire()
	LobbyToArena.Event:Connect(function(thumbnails)
		playerThumbnails = thumbnails
	end)
	
	if #gamePlayers == 6 then
		for i = 3, 1, -1 do
			team1[i].RespawnLocation = workspace:FindFirstChild("Sword Fighting Arenas").Arena1.T1Spawn
			team2[i].RespawnLocation = workspace:FindFirstChild("Sword Fighting Arenas").Arena1.T2Spawn
		end
		

        -- I get an error on these lines saying thats attempting to index the userId with nil.
		local content1 = playerThumbnails[tostring(gamePlayers[1].UserId)]
		local content2 = playerThumbnails[tostring(gamePlayers[2].UserId)]
		local content3 = playerThumbnails[tostring(gamePlayers[3].UserId)]
		local content4 = playerThumbnails[tostring(gamePlayers[4].UserId)]
		local content5 = playerThumbnails[tostring(gamePlayers[5].UserId)]
		local content6 = playerThumbnails[tostring(gamePlayers[6].UserId)]

where is this “gamePlayers” table and what gets put inside of it, because from what i see theres no mention of a table labelled “gamePlayers” but there is mentions of something supposedly being put inside

2 Likes

Sorry its quite a big script so thats defined elsewhere, it just has the players inside it. That isn’t the issue I don’t think as I use the gamePlayers list all over the script with no issues

its not directly the issue but it is directly related to the issue, im kinda stuck without knowing what is inside of gamePlayers

1 Like

Maybe connect the LobbyToArena event before you fire the ArenaToLobby event?

1 Like

why was this the solution, i believe infact my message held nothing to lead to the solution

I just solved it myself in the end, so i thought I’d close the post. Thanks for any help tho

I’d recommend explaining what the solution turned out to be so that anyone else who comes across the thread with a similar script structure / setup that encounters the same issue will have a better idea of what they might need to do to fix it

1 Like
1 Like

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